Skip to content

Commit

Permalink
PHPStan Level 4
Browse files Browse the repository at this point in the history
  • Loading branch information
adrilo committed Jan 23, 2022
1 parent ea0a67d commit 6f1b67b
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 43 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 3
level: 4
paths:
- src
- tests
Expand Down
8 changes: 4 additions & 4 deletions src/Spout/Common/Entity/Style/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -78,7 +78,7 @@ class Style
/** @var bool */
private $hasSetBackgroundColor = false;

/** @var string Format */
/** @var string|null Format */
private $format;

/** @var bool */
Expand Down Expand Up @@ -110,7 +110,7 @@ public function setId($id)
}

/**
* @return Border
* @return Border|null
*/
public function getBorder()
{
Expand Down Expand Up @@ -467,7 +467,7 @@ public function setFormat($format)
}

/**
* @return string
* @return string|null
*/
public function getFormat()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Common/Helper/GlobalFunctionsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function fgetcsv($handle, $length = null, $delimiter = null, $enclosure =
* @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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Reader/CSV/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function getConcreteSheetIterator()
*/
protected function closeReader()
{
if ($this->filePointer) {
if (is_resource($this->filePointer)) {
$this->globalFunctionsHelper->fclose($this->filePointer);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Reader/CSV/RowIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Reader/ODS/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function getConcreteSheetIterator()
*/
protected function closeReader()
{
if ($this->zip) {
if ($this->zip !== null) {
$this->zip->close();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Reader/ReaderAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function close()
$this->closeReader();

$sheetIterator = $this->getConcreteSheetIterator();
if ($sheetIterator) {
if ($sheetIterator !== null) {
$sheetIterator->end();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Reader/XLSX/Creator/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ManagerFactory
/** @var CachingStrategyFactory */
private $cachingStrategyFactory;

/** @var WorkbookRelationshipsManager */
/** @var WorkbookRelationshipsManager|null */
private $cachedWorkbookRelationshipsManager;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function isInMemoryStrategyUsageSafe($sharedStringsUniqueCount)

$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 {
Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Reader/XLSX/Manager/SharedStringsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function getStringAtIndex($sharedStringIndex)
*/
public function cleanup()
{
if ($this->cachingStrategy) {
if ($this->cachingStrategy !== null) {
$this->cachingStrategy->clearCache();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Spout/Reader/XLSX/Manager/StyleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Spout/Reader/XLSX/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ protected function getConcreteSheetIterator()
*/
protected function closeReader()
{
if ($this->zip) {
if ($this->zip !== null) {
$this->zip->close();
}

if ($this->sharedStringsManager) {
if ($this->sharedStringsManager !== null) {
$this->sharedStringsManager->cleanup();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Spout/Writer/Common/Manager/Style/StyleMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ private function mergeCellProperties(Style $styleToUpdate, Style $style, Style $
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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/Spout/Writer/Common/Manager/WorkbookManagerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
abstract class WorkbookManagerAbstract implements WorkbookManagerInterface
{
/** @var Workbook The workbook to manage */
/** @var Workbook|null The workbook to manage */
protected $workbook;

/** @var OptionsManagerInterface */
Expand Down Expand Up @@ -92,7 +92,7 @@ abstract protected function getMaxRowsPerWorksheet();
abstract protected function getWorksheetFilePath(Sheet $sheet);

/**
* @return Workbook
* @return Workbook|null
*/
public function getWorkbook()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
interface WorkbookManagerInterface
{
/**
* @return Workbook
* @return Workbook|null
*/
public function getWorkbook();

Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Writer/WriterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function openToBrowser($outputFileName)
*/
protected function throwIfFilePointerIsNotAvailable()
{
if (!$this->filePointer) {
if (!is_resource($this->filePointer)) {
throw new IOException('File pointer has not be opened');
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/Spout/Writer/WriterMultiSheetsAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand All @@ -25,7 +24,7 @@ abstract class WriterMultiSheetsAbstract extends WriterAbstract
/** @var ManagerFactoryInterface */
private $managerFactory;

/** @var WorkbookManagerInterface */
/** @var WorkbookManagerInterface|null */
private $workbookManager;

/**
Expand Down Expand Up @@ -66,7 +65,7 @@ public function setShouldCreateNewSheetsAutomatically($shouldCreateNewSheetsAuto
*/
protected function openWriter()
{
if (!$this->workbookManager) {
if ($this->workbookManager === null) {
$this->workbookManager = $this->managerFactory->createWorkbookManager($this->optionsManager);
$this->workbookManager->addNewSheetAndMakeItCurrent();
}
Expand All @@ -85,7 +84,6 @@ public function getSheets()
$externalSheets = [];
$worksheets = $this->workbookManager->getWorksheets();

/** @var Worksheet $worksheet */
foreach ($worksheets as $worksheet) {
$externalSheets[] = $worksheet->getExternalSheet();
}
Expand Down Expand Up @@ -143,7 +141,7 @@ public function setCurrentSheet($sheet)
*/
protected function throwIfWorkbookIsNotAvailable()
{
if (!$this->workbookManager->getWorkbook()) {
if ($this->workbookManager->getWorkbook() === null) {
throw new WriterNotOpenedException('The writer must be opened before performing this action.');
}
}
Expand All @@ -162,7 +160,7 @@ protected function addRowToWriter(Row $row)
*/
protected function closeWriter()
{
if ($this->workbookManager) {
if ($this->workbookManager !== null) {
$this->workbookManager->close($this->filePointer);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Spout/Writer/XLSX/Creator/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ private function createWorksheetManager(
$styleMerger,
$sharedStringsManager,
$stringsEscaper,
$stringsHelper,
$this->entityFactory
$stringsHelper
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Spout/Writer/XLSX/Manager/SharedStringsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct($xlFolder, $stringsEscaper)
*/
protected function throwIfSharedStringsFilePointerIsNotAvailable()
{
if (!$this->sharedStringsFilePointer) {
if (!is_resource($this->sharedStringsFilePointer)) {
throw new IOException('Unable to open shared strings file for writing.');
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/Spout/Writer/XLSX/Manager/WorksheetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand Down Expand Up @@ -60,9 +59,6 @@ class WorksheetManager implements WorksheetManagerInterface
/** @var StringHelper String helper */
private $stringHelper;

/** @var InternalEntityFactory Factory to create entities */
private $entityFactory;

/**
* WorksheetManager constructor.
*
Expand All @@ -73,7 +69,6 @@ class WorksheetManager implements WorksheetManagerInterface
* @param SharedStringsManager $sharedStringsManager
* @param XLSXEscaper $stringsEscaper
* @param StringHelper $stringHelper
* @param InternalEntityFactory $entityFactory
*/
public function __construct(
OptionsManagerInterface $optionsManager,
Expand All @@ -82,8 +77,7 @@ public function __construct(
StyleMerger $styleMerger,
SharedStringsManager $sharedStringsManager,
XLSXEscaper $stringsEscaper,
StringHelper $stringHelper,
InternalEntityFactory $entityFactory
StringHelper $stringHelper
) {
$this->shouldUseInlineStrings = $optionsManager->getOption(Options::SHOULD_USE_INLINE_STRINGS);
$this->rowManager = $rowManager;
Expand All @@ -92,7 +86,6 @@ public function __construct(
$this->sharedStringsManager = $sharedStringsManager;
$this->stringsEscaper = $stringsEscaper;
$this->stringHelper = $stringHelper;
$this->entityFactory = $entityFactory;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Spout/Writer/CSV/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function testWriteShouldSupportedEscapedCharacters()
* @param string $fieldDelimiter
* @param string $fieldEnclosure
* @param bool $shouldAddBOM
* @return string|null
* @return string
*/
private function writeToCsvFileAndReturnWrittenContent($allRows, $fileName, $fieldDelimiter = ',', $fieldEnclosure = '"', $shouldAddBOM = true)
{
Expand Down
1 change: 0 additions & 1 deletion tests/Spout/Writer/XLSX/WriterWithStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ public function testBordersCorrectOrder()
$borderParts = $borderNode->childNodes;
$ordering = [];

/** @var \DOMText $part */
foreach ($borderParts as $part) {
if ($part instanceof \DOMElement) {
$ordering[] = $part->nodeName;
Expand Down

0 comments on commit 6f1b67b

Please sign in to comment.