Add phpstan until level 7

This commit is contained in:
Antoine Lamirault committed 2021-09-18 18:09:14 +02:00
1 parent ab973cab34
commit bfb7c2c68f
114 files changed
+527 -319

No files matched your search

@@ -152,7 +152,7 @@ class InternalEntityFactory implements InternalEntityFactoryInterface
}
/**
* @param $xmlReader
* @param XMLReader $xmlReader
* @return XMLProcessor
*/
public function createXMLProcessor($xmlReader)
+4 -1
View File
@@ -10,7 +10,10 @@ use Box\Spout\Common\Exception\InvalidArgumentException;
*/
class CellHelper
{
// Using ord() is super slow... Using a pre-computed hash table instead.
/**
* Using ord() is super slow... Using a pre-computed hash table instead.
* @var array<string, int>
*/
private static $columnLetterToIndexMapping = [
'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6,
'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13,
@@ -74,7 +74,7 @@ class CellValueFormatter
/**
* Returns the (unescaped) correctly marshalled, cell value associated to the given XML node.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @throws InvalidValueException If the value is not valid
* @return string|int|float|bool|\DateTime The value associated with the cell
*/
@@ -110,7 +110,7 @@ class CellValueFormatter
/**
* Returns the cell's string value from a node's nested value node
*
* @param \DOMNode $node
* @param \DOMElement $node
* @return string The value associated with the cell
*/
protected function getVNodeValue($node)
@@ -125,7 +125,7 @@ class CellValueFormatter
/**
* Returns the cell String value where string is inline.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @return string The value associated with the cell
*/
protected function formatInlineStringCellValue($node)
@@ -210,6 +210,7 @@ class CellValueFormatter
protected function formatExcelTimestampValue($nodeValue, $cellStyleId)
{
if ($this->isValidTimestampValue($nodeValue)) {
/** @var \DateTime $cellValue */
$cellValue = $this->formatExcelTimestampValueAsDateTimeValue($nodeValue, $cellStyleId);
} else {
throw new InvalidValueException($nodeValue);
@@ -251,6 +252,7 @@ class CellValueFormatter
$timeRemainder = \fmod($nodeValue, 1);
$secondsRemainder = \round($timeRemainder * self::NUM_SECONDS_IN_ONE_DAY, 0);
/** @var \DateTime $dateObj */
$dateObj = \DateTime::createFromFormat('|Y-m-d', $baseDate);
$dateObj->modify('+' . $daysSinceBaseDate . 'days');
$dateObj->modify('+' . $secondsRemainder . 'seconds');
@@ -16,7 +16,7 @@ class DateFormatHelper
* This map is used to replace Excel format characters by their PHP equivalent.
* Keys should be ordered from longest to smallest.
*
* @var array Mapping between Excel format characters and PHP format characters
* @var array<string, array> Mapping between Excel format characters and PHP format characters
*/
private static $excelDateFormatToPHPDateFormatMapping = [
self::KEY_GENERAL => [
@@ -104,6 +104,7 @@ class DateFormatHelper
// For instance, ["Day " dd] should become [\D\a\y\ dd]
$phpDateFormat = \preg_replace_callback('/"(.+?)"/', function ($matches) {
$stringToEscape = $matches[1];
/** @var string[] $letters */
$letters = \preg_split('//u', $stringToEscape, -1, PREG_SPLIT_NO_EMPTY);
return '\\' . \implode('\\', $letters);
@@ -98,7 +98,7 @@ class CachingStrategyFactory
/**
* Returns the PHP "memory_limit" in Kilobytes
*
* @return float
* @return int
*/
protected function getMemoryLimitInKB()
{
@@ -133,6 +133,9 @@ class CachingStrategyFactory
*/
protected function getMemoryLimitFromIni()
{
return \ini_get('memory_limit');
/** @var string $memoryLimit */
$memoryLimit = \ini_get('memory_limit');
return $memoryLimit;
}
}
@@ -32,7 +32,7 @@ class FileBasedStrategy implements CachingStrategyInterface
*/
protected $maxNumStringsPerTempFile;
/** @var resource Pointer to the last temp file a shared string was written to */
/** @var resource|null Pointer to the last temp file a shared string was written to */
protected $tempFilePointer;
/**
@@ -42,7 +42,7 @@ class FileBasedStrategy implements CachingStrategyInterface
protected $inMemoryTempFilePath;
/**
* @var array Contents of the temporary file that was last read
* @var array<string> Contents of the temporary file that was last read
* @see CachingStrategyFactory::MAX_NUM_STRINGS_PER_TEMP_FILE
*/
protected $inMemoryTempFileContents;
@@ -78,7 +78,9 @@ class FileBasedStrategy implements CachingStrategyInterface
if ($this->tempFilePointer) {
$this->globalFunctionsHelper->fclose($this->tempFilePointer);
}
$this->tempFilePointer = $this->globalFunctionsHelper->fopen($tempFilePath, 'w');
/** @var resource $tempFilePointer */
$tempFilePointer = $this->globalFunctionsHelper->fopen($tempFilePath, 'w');
$this->tempFilePointer = $tempFilePointer;
}
// The shared string retrieval logic expects each cell data to be on one line only
@@ -12,7 +12,7 @@ use Box\Spout\Reader\Exception\SharedStringNotFoundException;
*/
class InMemoryStrategy implements CachingStrategyInterface
{
/** @var \SplFixedArray Array used to cache the shared strings */
/** @var \SplFixedArray<string> Array used to cache the shared strings */
protected $inMemoryCache;
/** @var bool Whether the cache has been closed */
@@ -43,13 +43,13 @@ class SharedStringsManager
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;
/** @var HelperFactory $helperFactory Factory to create helpers */
/** @var HelperFactory Factory to create helpers */
protected $helperFactory;
/** @var CachingStrategyFactory Factory to create shared strings caching strategies */
protected $cachingStrategyFactory;
/** @var CachingStrategyInterface The best caching strategy for storing shared strings */
/** @var CachingStrategyInterface|null The best caching strategy for storing shared strings */
protected $cachingStrategy;
/**
@@ -182,6 +182,7 @@ class SharedStringsManager
$sharedStringValue = '';
// NOTE: expand() will automatically decode all XML entities of the child nodes
/** @var \DOMElement $siNode */
$siNode = $xmlReader->expand();
$textNodes = $siNode->getElementsByTagName(self::XML_NODE_T);
@@ -54,7 +54,7 @@ class SheetManager
/** @var \Box\Spout\Common\Helper\Escaper\XLSX Used to unescape XML data */
protected $escaper;
/** @var array List of sheets */
/** @var array<Sheet> List of sheets */
protected $sheets;
/** @var int Index of the sheet currently read */
@@ -28,7 +28,7 @@ class StyleManager
/**
* @see https://msdn.microsoft.com/en-us/library/ff529597(v=office.12).aspx
* @var array Mapping between built-in numFmtId and the associated format - for dates only
* @var array<int, string> Mapping between built-in numFmtId and the associated format - for dates only
*/
protected static $builtinNumFmtIdToNumFormatMapping = [
14 => 'm/d/yyyy', // @NOTE: ECMA spec is 'mm-dd-yy'
@@ -57,16 +57,16 @@ class StyleManager
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;
/** @var array Array containing the IDs of built-in number formats indicating a date */
/** @var int[]|string[] 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<int,string> Array containing a mapping NUM_FMT_ID => FORMAT_CODE */
protected $customNumberFormats;
/** @var array Array containing a mapping STYLE_ID => [STYLE_ATTRIBUTES] */
/** @var array<mixed> 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 */
/** @var array<int, bool> Cache containing a mapping NUM_FMT_ID => IS_DATE_FORMAT. Used to avoid lots of recalculations */
protected $numFmtIdToIsDateFormatCache = [];
/**
@@ -189,7 +189,7 @@ class StyleManager
}
/**
* @return array The custom number formats
* @return array<int,string> The custom number formats
*/
protected function getCustomNumberFormats()
{
@@ -201,7 +201,7 @@ class StyleManager
}
/**
* @return array The styles attributes
* @return array<mixed> The styles attributes
*/
protected function getStylesAttributes()
{
@@ -213,7 +213,7 @@ class StyleManager
}
/**
* @param array $styleAttributes Array containing the style attributes (2 keys: "applyNumberFormat" and "numFmtId")
* @param array<string, mixed> $styleAttributes Array containing the style attributes (2 keys: "applyNumberFormat" and "numFmtId")
* @return bool Whether the style with the given attributes indicates that the number is a date
*/
protected function doesStyleIndicateDate($styleAttributes)
@@ -33,7 +33,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<string, string> Cache of the already read workbook relationships: [TYPE] => [FILE_NAME] */
private $cachedWorkbookRelationships;
/**
@@ -107,7 +107,7 @@ class WorkbookRelationshipsManager
* It caches the result so that the file is read only once.
*
* @throws \Box\Spout\Common\Exception\IOException If workbook.xml.rels can't be read
* @return array
* @return array<string, string>
*/
private function getWorkbookRelationships()
{
+2 -2
View File
@@ -20,10 +20,10 @@ class Reader extends ReaderAbstract
/** @var ManagerFactory */
protected $managerFactory;
/** @var \ZipArchive */
/** @var \ZipArchive|null */
protected $zip;
/** @var \Box\Spout\Reader\XLSX\Manager\SharedStringsManager Manages shared strings */
/** @var \Box\Spout\Reader\XLSX\Manager\SharedStringsManager|null Manages shared strings */
protected $sharedStringsManager;
/** @var SheetIterator To iterator over the XLSX sheets */
+4 -2
View File
@@ -17,6 +17,7 @@ use Box\Spout\Reader\XLSX\Helper\CellValueFormatter;
/**
* Class RowIterator
* @implements IteratorInterface<Row>
*/
class RowIterator implements IteratorInterface
{
@@ -35,7 +36,7 @@ class RowIterator implements IteratorInterface
/** @var string Path of the XLSX file being read */
protected $filePath;
/** @var string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml */
/** @var string Path of the sheet data XML file as in [Content_Types].xml */
protected $sheetDataXMLFilePath;
/** @var \Box\Spout\Reader\Wrapper\XMLReader The XMLReader object that will help read sheet's XML data */
@@ -276,6 +277,7 @@ class RowIterator implements IteratorInterface
$currentColumnIndex = $this->getColumnIndex($xmlReader);
// NOTE: expand() will automatically decode all XML entities of the child nodes
/** @var \DOMElement $node */
$node = $xmlReader->expand();
$cell = $this->getCell($node);
@@ -352,7 +354,7 @@ class RowIterator implements IteratorInterface
/**
* Returns the cell with (unescaped) correctly marshalled, cell value associated to the given XML node.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @return Cell The cell set with the associated with the cell
*/
protected function getCell($node)
+1
View File
@@ -9,6 +9,7 @@ use Box\Spout\Reader\XLSX\Manager\SheetManager;
/**
* Class SheetIterator
* Iterate over XLSX sheet.
* @implements IteratorInterface<Sheet>
*/
class SheetIterator implements IteratorInterface
{