diff --git a/phpstan.neon b/phpstan.neon index fddfd9c..772c5cc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 3 + level: 4 paths: - src - tests diff --git a/src/Spout/Common/Entity/Style/Style.php b/src/Spout/Common/Entity/Style/Style.php index b5f38f9..0af1450 100644 --- a/src/Spout/Common/Entity/Style/Style.php +++ b/src/Spout/Common/Entity/Style/Style.php @@ -66,7 +66,7 @@ class Style /** @var bool Whether the wrap text property was set */ private $hasSetWrapText = false; - /** @var Border */ + /** @var Border|null */ private $border; /** @var bool Whether border properties should be applied */ @@ -78,7 +78,7 @@ class Style /** @var bool */ private $hasSetBackgroundColor = false; - /** @var string Format */ + /** @var string|null Format */ private $format; /** @var bool */ @@ -110,7 +110,7 @@ class Style } /** - * @return Border + * @return Border|null */ public function getBorder() { @@ -467,7 +467,7 @@ class Style } /** - * @return string + * @return string|null */ public function getFormat() { diff --git a/src/Spout/Common/Helper/GlobalFunctionsHelper.php b/src/Spout/Common/Helper/GlobalFunctionsHelper.php index c5c92bc..5068227 100644 --- a/src/Spout/Common/Helper/GlobalFunctionsHelper.php +++ b/src/Spout/Common/Helper/GlobalFunctionsHelper.php @@ -103,7 +103,7 @@ class GlobalFunctionsHelper * @param array $fields * @param string|null $delimiter * @param string|null $enclosure - * @return int + * @return int|false */ public function fputcsv($handle, array $fields, $delimiter = null, $enclosure = null) { diff --git a/src/Spout/Reader/CSV/Reader.php b/src/Spout/Reader/CSV/Reader.php index 942acc5..2597067 100644 --- a/src/Spout/Reader/CSV/Reader.php +++ b/src/Spout/Reader/CSV/Reader.php @@ -142,7 +142,7 @@ class Reader extends ReaderAbstract */ protected function closeReader() { - if ($this->filePointer) { + if (is_resource($this->filePointer)) { $this->globalFunctionsHelper->fclose($this->filePointer); } diff --git a/src/Spout/Reader/CSV/RowIterator.php b/src/Spout/Reader/CSV/RowIterator.php index 233a14a..dfa2688 100644 --- a/src/Spout/Reader/CSV/RowIterator.php +++ b/src/Spout/Reader/CSV/RowIterator.php @@ -21,7 +21,7 @@ class RowIterator implements IteratorInterface */ public const MAX_READ_BYTES_PER_LINE = 0; - /** @var resource Pointer to the CSV file to read */ + /** @var resource|null Pointer to the CSV file to read */ protected $filePointer; /** @var int Number of read rows */ diff --git a/src/Spout/Reader/ODS/Reader.php b/src/Spout/Reader/ODS/Reader.php index d07dbb4..00a39bd 100644 --- a/src/Spout/Reader/ODS/Reader.php +++ b/src/Spout/Reader/ODS/Reader.php @@ -69,7 +69,7 @@ class Reader extends ReaderAbstract */ protected function closeReader() { - if ($this->zip) { + if ($this->zip !== null) { $this->zip->close(); } } diff --git a/src/Spout/Reader/ReaderAbstract.php b/src/Spout/Reader/ReaderAbstract.php index 1ef1c20..0c469a1 100644 --- a/src/Spout/Reader/ReaderAbstract.php +++ b/src/Spout/Reader/ReaderAbstract.php @@ -233,7 +233,7 @@ abstract class ReaderAbstract implements ReaderInterface $this->closeReader(); $sheetIterator = $this->getConcreteSheetIterator(); - if ($sheetIterator) { + if ($sheetIterator !== null) { $sheetIterator->end(); } diff --git a/src/Spout/Reader/XLSX/Creator/ManagerFactory.php b/src/Spout/Reader/XLSX/Creator/ManagerFactory.php index d23a53f..e69d429 100644 --- a/src/Spout/Reader/XLSX/Creator/ManagerFactory.php +++ b/src/Spout/Reader/XLSX/Creator/ManagerFactory.php @@ -21,7 +21,7 @@ class ManagerFactory /** @var CachingStrategyFactory */ private $cachingStrategyFactory; - /** @var WorkbookRelationshipsManager */ + /** @var WorkbookRelationshipsManager|null */ private $cachedWorkbookRelationshipsManager; /** diff --git a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php index 9afec2f..c36b911 100644 --- a/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php +++ b/src/Spout/Reader/XLSX/Manager/SharedStringsCaching/CachingStrategyFactory.php @@ -84,7 +84,7 @@ class CachingStrategyFactory $memoryAvailable = $this->getMemoryLimitInKB(); - if ($memoryAvailable === -1) { + if ((int) $memoryAvailable === -1) { // if cannot get memory limit or if memory limit set as unlimited, don't trust and play safe $isInMemoryStrategyUsageSafe = ($sharedStringsUniqueCount < self::MAX_NUM_STRINGS_PER_TEMP_FILE); } else { diff --git a/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php b/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php index 85d0103..fcf2a2b 100644 --- a/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php +++ b/src/Spout/Reader/XLSX/Manager/SharedStringsManager.php @@ -242,7 +242,7 @@ class SharedStringsManager */ public function cleanup() { - if ($this->cachingStrategy) { + if ($this->cachingStrategy !== null) { $this->cachingStrategy->clearCache(); } } diff --git a/src/Spout/Reader/XLSX/Manager/StyleManager.php b/src/Spout/Reader/XLSX/Manager/StyleManager.php index 71eeead..6435f7c 100644 --- a/src/Spout/Reader/XLSX/Manager/StyleManager.php +++ b/src/Spout/Reader/XLSX/Manager/StyleManager.php @@ -60,10 +60,10 @@ class StyleManager /** @var array Array containing the IDs of built-in number formats indicating a date */ protected $builtinNumFmtIdIndicatingDates; - /** @var array Array containing a mapping NUM_FMT_ID => FORMAT_CODE */ + /** @var array|null Array containing a mapping NUM_FMT_ID => FORMAT_CODE */ protected $customNumberFormats; - /** @var array Array containing a mapping STYLE_ID => [STYLE_ATTRIBUTES] */ + /** @var array|null Array containing a mapping STYLE_ID => [STYLE_ATTRIBUTES] */ protected $stylesAttributes; /** @var array Cache containing a mapping NUM_FMT_ID => IS_DATE_FORMAT. Used to avoid lots of recalculations */ diff --git a/src/Spout/Reader/XLSX/Manager/WorkbookRelationshipsManager.php b/src/Spout/Reader/XLSX/Manager/WorkbookRelationshipsManager.php index 7199f50..e022b34 100644 --- a/src/Spout/Reader/XLSX/Manager/WorkbookRelationshipsManager.php +++ b/src/Spout/Reader/XLSX/Manager/WorkbookRelationshipsManager.php @@ -34,7 +34,7 @@ class WorkbookRelationshipsManager /** @var InternalEntityFactory Factory to create entities */ private $entityFactory; - /** @var array Cache of the already read workbook relationships: [TYPE] => [FILE_NAME] */ + /** @var array|null Cache of the already read workbook relationships: [TYPE] => [FILE_NAME] */ private $cachedWorkbookRelationships; /** diff --git a/src/Spout/Reader/XLSX/Reader.php b/src/Spout/Reader/XLSX/Reader.php index 689f6e2..a031bb7 100644 --- a/src/Spout/Reader/XLSX/Reader.php +++ b/src/Spout/Reader/XLSX/Reader.php @@ -119,11 +119,11 @@ class Reader extends ReaderAbstract */ protected function closeReader() { - if ($this->zip) { + if ($this->zip !== null) { $this->zip->close(); } - if ($this->sharedStringsManager) { + if ($this->sharedStringsManager !== null) { $this->sharedStringsManager->cleanup(); } } diff --git a/src/Spout/Writer/Common/Manager/Style/StyleMerger.php b/src/Spout/Writer/Common/Manager/Style/StyleMerger.php index 806c8d5..cdc45d5 100644 --- a/src/Spout/Writer/Common/Manager/Style/StyleMerger.php +++ b/src/Spout/Writer/Common/Manager/Style/StyleMerger.php @@ -88,10 +88,10 @@ class StyleMerger if (!$style->hasSetCellAlignment() && $baseStyle->shouldApplyCellAlignment()) { $styleToUpdate->setCellAlignment($baseStyle->getCellAlignment()); } - if (!$style->getBorder() && $baseStyle->shouldApplyBorder()) { + if ($style->getBorder() === null && $baseStyle->shouldApplyBorder()) { $styleToUpdate->setBorder($baseStyle->getBorder()); } - if (!$style->getFormat() && $baseStyle->shouldApplyFormat()) { + if ($style->getFormat() === null && $baseStyle->shouldApplyFormat()) { $styleToUpdate->setFormat($baseStyle->getFormat()); } if (!$style->shouldApplyBackgroundColor() && $baseStyle->shouldApplyBackgroundColor()) { diff --git a/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php b/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php index 653778c..9b25e15 100644 --- a/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php +++ b/src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php @@ -23,7 +23,7 @@ use Box\Spout\Writer\Exception\WriterException; */ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface { - /** @var Workbook The workbook to manage */ + /** @var Workbook|null The workbook to manage */ protected $workbook; /** @var OptionsManagerInterface */ @@ -92,7 +92,7 @@ abstract class WorkbookManagerAbstract implements WorkbookManagerInterface abstract protected function getWorksheetFilePath(Sheet $sheet); /** - * @return Workbook + * @return Workbook|null */ public function getWorkbook() { diff --git a/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php b/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php index aed304a..526163d 100644 --- a/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php +++ b/src/Spout/Writer/Common/Manager/WorkbookManagerInterface.php @@ -17,7 +17,7 @@ use Box\Spout\Writer\Exception\WriterException; interface WorkbookManagerInterface { /** - * @return Workbook + * @return Workbook|null */ public function getWorkbook(); diff --git a/src/Spout/Writer/WriterAbstract.php b/src/Spout/Writer/WriterAbstract.php index 36a583f..fa43c97 100644 --- a/src/Spout/Writer/WriterAbstract.php +++ b/src/Spout/Writer/WriterAbstract.php @@ -169,7 +169,7 @@ abstract class WriterAbstract implements WriterInterface */ protected function throwIfFilePointerIsNotAvailable() { - if (!$this->filePointer) { + if (!is_resource($this->filePointer)) { throw new IOException('File pointer has not be opened'); } } diff --git a/src/Spout/Writer/WriterMultiSheetsAbstract.php b/src/Spout/Writer/WriterMultiSheetsAbstract.php index 8170b67..18b40bd 100644 --- a/src/Spout/Writer/WriterMultiSheetsAbstract.php +++ b/src/Spout/Writer/WriterMultiSheetsAbstract.php @@ -9,7 +9,6 @@ use Box\Spout\Common\Manager\OptionsManagerInterface; use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface; use Box\Spout\Writer\Common\Entity\Options; use Box\Spout\Writer\Common\Entity\Sheet; -use Box\Spout\Writer\Common\Entity\Worksheet; use Box\Spout\Writer\Common\Manager\WorkbookManagerInterface; use Box\Spout\Writer\Exception\SheetNotFoundException; use Box\Spout\Writer\Exception\WriterAlreadyOpenedException; @@ -25,7 +24,7 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract /** @var ManagerFactoryInterface */ private $managerFactory; - /** @var WorkbookManagerInterface */ + /** @var WorkbookManagerInterface|null */ private $workbookManager; /** @@ -66,7 +65,7 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract */ protected function openWriter() { - if (!$this->workbookManager) { + if ($this->workbookManager === null) { $this->workbookManager = $this->managerFactory->createWorkbookManager($this->optionsManager); $this->workbookManager->addNewSheetAndMakeItCurrent(); } @@ -85,7 +84,6 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract $externalSheets = []; $worksheets = $this->workbookManager->getWorksheets(); - /** @var Worksheet $worksheet */ foreach ($worksheets as $worksheet) { $externalSheets[] = $worksheet->getExternalSheet(); } @@ -143,7 +141,7 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract */ protected function throwIfWorkbookIsNotAvailable() { - if (!$this->workbookManager->getWorkbook()) { + if ($this->workbookManager->getWorkbook() === null) { throw new WriterNotOpenedException('The writer must be opened before performing this action.'); } } @@ -162,7 +160,7 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract */ protected function closeWriter() { - if ($this->workbookManager) { + if ($this->workbookManager !== null) { $this->workbookManager->close($this->filePointer); } } diff --git a/src/Spout/Writer/XLSX/Creator/ManagerFactory.php b/src/Spout/Writer/XLSX/Creator/ManagerFactory.php index aa3bcd5..5865268 100644 --- a/src/Spout/Writer/XLSX/Creator/ManagerFactory.php +++ b/src/Spout/Writer/XLSX/Creator/ManagerFactory.php @@ -91,8 +91,7 @@ class ManagerFactory implements ManagerFactoryInterface $styleMerger, $sharedStringsManager, $stringsEscaper, - $stringsHelper, - $this->entityFactory + $stringsHelper ); } diff --git a/src/Spout/Writer/XLSX/Manager/SharedStringsManager.php b/src/Spout/Writer/XLSX/Manager/SharedStringsManager.php index da21f7b..9a82cff 100644 --- a/src/Spout/Writer/XLSX/Manager/SharedStringsManager.php +++ b/src/Spout/Writer/XLSX/Manager/SharedStringsManager.php @@ -59,7 +59,7 @@ EOD; */ protected function throwIfSharedStringsFilePointerIsNotAvailable() { - if (!$this->sharedStringsFilePointer) { + if (!is_resource($this->sharedStringsFilePointer)) { throw new IOException('Unable to open shared strings file for writing.'); } } diff --git a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php index 25bb88d..6025442 100644 --- a/src/Spout/Writer/XLSX/Manager/WorksheetManager.php +++ b/src/Spout/Writer/XLSX/Manager/WorksheetManager.php @@ -10,7 +10,6 @@ use Box\Spout\Common\Exception\IOException; use Box\Spout\Common\Helper\Escaper\XLSX as XLSXEscaper; use Box\Spout\Common\Helper\StringHelper; use Box\Spout\Common\Manager\OptionsManagerInterface; -use Box\Spout\Writer\Common\Creator\InternalEntityFactory; use Box\Spout\Writer\Common\Entity\Options; use Box\Spout\Writer\Common\Entity\Worksheet; use Box\Spout\Writer\Common\Helper\CellHelper; @@ -60,9 +59,6 @@ EOD; /** @var StringHelper String helper */ private $stringHelper; - /** @var InternalEntityFactory Factory to create entities */ - private $entityFactory; - /** * WorksheetManager constructor. * @@ -73,7 +69,6 @@ EOD; * @param SharedStringsManager $sharedStringsManager * @param XLSXEscaper $stringsEscaper * @param StringHelper $stringHelper - * @param InternalEntityFactory $entityFactory */ public function __construct( OptionsManagerInterface $optionsManager, @@ -82,8 +77,7 @@ EOD; StyleMerger $styleMerger, SharedStringsManager $sharedStringsManager, XLSXEscaper $stringsEscaper, - StringHelper $stringHelper, - InternalEntityFactory $entityFactory + StringHelper $stringHelper ) { $this->shouldUseInlineStrings = $optionsManager->getOption(Options::SHOULD_USE_INLINE_STRINGS); $this->rowManager = $rowManager; @@ -92,7 +86,6 @@ EOD; $this->sharedStringsManager = $sharedStringsManager; $this->stringsEscaper = $stringsEscaper; $this->stringHelper = $stringHelper; - $this->entityFactory = $entityFactory; } /** diff --git a/tests/Spout/Writer/CSV/WriterTest.php b/tests/Spout/Writer/CSV/WriterTest.php index deb3f22..ccf5181 100644 --- a/tests/Spout/Writer/CSV/WriterTest.php +++ b/tests/Spout/Writer/CSV/WriterTest.php @@ -193,7 +193,7 @@ class WriterTest extends TestCase * @param string $fieldDelimiter * @param string $fieldEnclosure * @param bool $shouldAddBOM - * @return string|null + * @return string */ private function writeToCsvFileAndReturnWrittenContent($allRows, $fileName, $fieldDelimiter = ',', $fieldEnclosure = '"', $shouldAddBOM = true) { diff --git a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php index 7237039..57859b6 100644 --- a/tests/Spout/Writer/XLSX/WriterWithStyleTest.php +++ b/tests/Spout/Writer/XLSX/WriterWithStyleTest.php @@ -475,7 +475,6 @@ class WriterWithStyleTest extends TestCase $borderParts = $borderNode->childNodes; $ordering = []; - /** @var \DOMText $part */ foreach ($borderParts as $part) { if ($part instanceof \DOMElement) { $ordering[] = $part->nodeName;