PHPStan Level 4
This commit is contained in:
		
							parent
							
								
									ea0a67d283
								
							
						
					
					
						commit
						6f1b67b39d
					
				@ -1,5 +1,5 @@
 | 
			
		||||
parameters:
 | 
			
		||||
    level: 3
 | 
			
		||||
    level: 4
 | 
			
		||||
    paths:
 | 
			
		||||
        - src
 | 
			
		||||
        - tests
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -142,7 +142,7 @@ class Reader extends ReaderAbstract
 | 
			
		||||
     */
 | 
			
		||||
    protected function closeReader()
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->filePointer) {
 | 
			
		||||
        if (is_resource($this->filePointer)) {
 | 
			
		||||
            $this->globalFunctionsHelper->fclose($this->filePointer);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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 */
 | 
			
		||||
 | 
			
		||||
@ -69,7 +69,7 @@ class Reader extends ReaderAbstract
 | 
			
		||||
     */
 | 
			
		||||
    protected function closeReader()
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->zip) {
 | 
			
		||||
        if ($this->zip !== null) {
 | 
			
		||||
            $this->zip->close();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -233,7 +233,7 @@ abstract class ReaderAbstract implements ReaderInterface
 | 
			
		||||
            $this->closeReader();
 | 
			
		||||
 | 
			
		||||
            $sheetIterator = $this->getConcreteSheetIterator();
 | 
			
		||||
            if ($sheetIterator) {
 | 
			
		||||
            if ($sheetIterator !== null) {
 | 
			
		||||
                $sheetIterator->end();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ class ManagerFactory
 | 
			
		||||
    /** @var CachingStrategyFactory */
 | 
			
		||||
    private $cachingStrategyFactory;
 | 
			
		||||
 | 
			
		||||
    /** @var WorkbookRelationshipsManager */
 | 
			
		||||
    /** @var WorkbookRelationshipsManager|null */
 | 
			
		||||
    private $cachedWorkbookRelationshipsManager;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -242,7 +242,7 @@ class SharedStringsManager
 | 
			
		||||
     */
 | 
			
		||||
    public function cleanup()
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->cachingStrategy) {
 | 
			
		||||
        if ($this->cachingStrategy !== null) {
 | 
			
		||||
            $this->cachingStrategy->clearCache();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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 */
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -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();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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()) {
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ use Box\Spout\Writer\Exception\WriterException;
 | 
			
		||||
interface WorkbookManagerInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * @return Workbook
 | 
			
		||||
     * @return Workbook|null
 | 
			
		||||
     */
 | 
			
		||||
    public function getWorkbook();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -91,8 +91,7 @@ class ManagerFactory implements ManagerFactoryInterface
 | 
			
		||||
            $styleMerger,
 | 
			
		||||
            $sharedStringsManager,
 | 
			
		||||
            $stringsEscaper,
 | 
			
		||||
            $stringsHelper,
 | 
			
		||||
            $this->entityFactory
 | 
			
		||||
            $stringsHelper
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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.');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user