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

@@ -84,7 +84,7 @@ class InternalEntityFactory implements InternalEntityFactoryInterface
}
/**
* @param array $cellValues
* @param array<mixed> $cellValues
* @return Row
*/
public function createRowFromArray(array $cellValues = [])
+7 -4
View File
@@ -13,7 +13,7 @@ use Box\Spout\Reader\ReaderAbstract;
*/
class Reader extends ReaderAbstract
{
/** @var resource Pointer to the file to be written */
/** @var resource|null Pointer to the file to be written */
protected $filePointer;
/** @var SheetIterator To iterator over the CSV unique "sheet" */
@@ -84,13 +84,16 @@ class Reader extends ReaderAbstract
*/
protected function openReader($filePath)
{
$this->originalAutoDetectLineEndings = \ini_get('auto_detect_line_endings');
/** @var string $autoDetectLineEndings */
$autoDetectLineEndings = \ini_get('auto_detect_line_endings');
$this->originalAutoDetectLineEndings = $autoDetectLineEndings;
\ini_set('auto_detect_line_endings', '1');
$this->filePointer = $this->globalFunctionsHelper->fopen($filePath, 'r');
if (!$this->filePointer) {
$filePointer = $this->globalFunctionsHelper->fopen($filePath, 'r');
if (!is_resource($filePointer)) {
throw new IOException("Could not open file $filePath for reading.");
}
$this->filePointer = $filePointer;
/** @var InternalEntityFactory $entityFactory */
$entityFactory = $this->entityFactory;
+6 -4
View File
@@ -13,6 +13,7 @@ use Box\Spout\Reader\IteratorInterface;
/**
* Class RowIterator
* Iterate over CSV rows.
* @implements IteratorInterface<Row>
*/
class RowIterator implements IteratorInterface
{
@@ -21,7 +22,7 @@ class RowIterator implements IteratorInterface
*/
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 */
@@ -147,6 +148,7 @@ class RowIterator implements IteratorInterface
if ($rowData !== false) {
// str_replace will replace NULL values by empty strings
/** @phpstan-ignore-next-line */
$rowDataBufferAsArray = \str_replace(null, null, $rowData);
$this->rowBuffer = $this->entityFactory->createRowFromArray($rowDataBufferAsArray);
$this->numReadRows++;
@@ -158,7 +160,7 @@ class RowIterator implements IteratorInterface
}
/**
* @param array|bool $currentRowData
* @param array<int, string>|bool $currentRowData
* @return bool Whether the data for the current row can be returned or if we need to keep reading
*/
protected function shouldReadNextRow($currentRowData)
@@ -179,7 +181,7 @@ class RowIterator implements IteratorInterface
* we remove manually whitespace with ltrim or rtrim (depending on the order of the bytes)
*
* @throws \Box\Spout\Common\Exception\EncodingConversionException If unable to convert data to UTF-8
* @return array|false The row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read
* @return array<int, string>|false The row for the current file pointer, encoded in UTF-8 or FALSE if nothing to read
*/
protected function getNextUTF8EncodedRow()
{
@@ -210,7 +212,7 @@ class RowIterator implements IteratorInterface
}
/**
* @param array|bool $lineData Array containing the cells value for the line
* @param array<mixed>|bool $lineData Array containing the cells value for the line
* @return bool Whether the given line is empty
*/
protected function isEmptyLine($lineData)
+1
View File
@@ -7,6 +7,7 @@ use Box\Spout\Reader\IteratorInterface;
/**
* Class SheetIterator
* Iterate over CSV unique "sheet".
* @implements IteratorInterface<Sheet>
*/
class SheetIterator implements IteratorInterface
{
@@ -2,7 +2,6 @@
namespace Box\Spout\Reader\Common\Creator;
use Box\Spout\Common\Exception\UnsupportedTypeException;
use Box\Spout\Common\Type;
use Box\Spout\Reader\ReaderInterface;
@@ -31,11 +30,10 @@ class ReaderEntityFactory
*/
public static function createCSVReader()
{
try {
return ReaderFactory::createFromType(Type::CSV);
} catch (UnsupportedTypeException $e) {
// should never happen
}
/** @var \Box\Spout\Reader\CSV\Reader $csvReader */
$csvReader = ReaderFactory::createFromType(Type::CSV);
return $csvReader;
}
/**
@@ -45,11 +43,10 @@ class ReaderEntityFactory
*/
public static function createXLSXReader()
{
try {
return ReaderFactory::createFromType(Type::XLSX);
} catch (UnsupportedTypeException $e) {
// should never happen
}
/** @var \Box\Spout\Reader\XLSX\Reader $xlsxReader */
$xlsxReader = ReaderFactory::createFromType(Type::XLSX);
return $xlsxReader;
}
/**
@@ -59,10 +56,9 @@ class ReaderEntityFactory
*/
public static function createODSReader()
{
try {
return ReaderFactory::createFromType(Type::ODS);
} catch (UnsupportedTypeException $e) {
// should never happen
}
/** @var \Box\Spout\Reader\ODS\Reader $odsReader */
$odsReader = ReaderFactory::createFromType(Type::ODS);
return $odsReader;
}
}
+7 -7
View File
@@ -25,7 +25,7 @@ class XMLProcessor
/** @var \Box\Spout\Reader\Wrapper\XMLReader The XMLReader object that will help read sheet's XML data */
protected $xmlReader;
/** @var array Registered callbacks */
/** @var array<string, array> Registered callbacks */
private $callbacks = [];
/**
@@ -39,7 +39,7 @@ class XMLProcessor
/**
* @param string $nodeName A callback may be triggered when a node with this name is read
* @param int $nodeType Type of the node [NODE_TYPE_START || NODE_TYPE_END]
* @param callable $callback Callback to execute when the read node has the given name and type
* @param array{object, string} $callback Callback to execute when the read node has the given name and type
* @return XMLProcessor
*/
public function registerCallback($nodeName, $nodeType, $callback)
@@ -66,8 +66,8 @@ class XMLProcessor
* Since some functions can be called a lot, we pre-process the callback to only return the elements that
* will be needed to invoke the callback later.
*
* @param callable $callback Array reference to a callback: [OBJECT, METHOD_NAME]
* @return array Associative array containing the elements needed to invoke the callback using Reflection
* @param array{object, string} $callback Array reference to a callback: [OBJECT, METHOD_NAME]
* @return array<string, mixed> Associative array containing the elements needed to invoke the callback using Reflection
*/
private function getInvokableCallbackData($callback)
{
@@ -113,7 +113,7 @@ class XMLProcessor
* @param string $nodeNamePossiblyWithPrefix Name of the node, possibly prefixed
* @param string $nodeNameWithoutPrefix Name of the same node, un-prefixed
* @param int $nodeType Type of the node [NODE_TYPE_START || NODE_TYPE_END]
* @return array|null Callback data to be used for execution when a node of the given name/type is read or NULL if none found
* @return array<mixed>|null Callback data to be used for execution when a node of the given name/type is read or NULL if none found
*/
private function getRegisteredCallbackData($nodeNamePossiblyWithPrefix, $nodeNameWithoutPrefix, $nodeType)
{
@@ -134,8 +134,8 @@ class XMLProcessor
}
/**
* @param array $callbackData Associative array containing data to invoke the callback using Reflection
* @param array $args Arguments to pass to the callback
* @param array<string, mixed> $callbackData Associative array containing data to invoke the callback using Reflection
* @param array<mixed> $args Arguments to pass to the callback
* @return int Callback response
*/
private function invokeCallback($callbackData, $args)
+2
View File
@@ -4,6 +4,8 @@ namespace Box\Spout\Reader;
/**
* Interface IteratorInterface
* @template TValue
* @extends \Iterator<int, TValue>
*/
interface IteratorInterface extends \Iterator
{
@@ -105,7 +105,7 @@ class InternalEntityFactory implements InternalEntityFactoryInterface
}
/**
* @param $xmlReader
* @param XMLReader $xmlReader
* @return XMLProcessor
*/
private function createXMLProcessor($xmlReader)
@@ -43,7 +43,7 @@ class CellValueFormatter
/** @var \Box\Spout\Common\Helper\Escaper\ODS Used to unescape XML data */
protected $escaper;
/** @var array List of XML nodes representing whitespaces and their corresponding value */
/** @var array<string, string> List of XML nodes representing whitespaces and their corresponding value */
private static $WHITESPACE_XML_NODES = [
self::XML_NODE_TEXT_S => ' ',
self::XML_NODE_TEXT_TAB => "\t",
@@ -64,7 +64,7 @@ class CellValueFormatter
* Returns the (unescaped) correctly marshalled, cell value associated to the given XML node.
* @see http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#refTable13
*
* @param \DOMNode $node
* @param \DOMElement $node
* @throws InvalidValueException If the node value is not valid
* @return string|int|float|bool|\DateTime|\DateInterval The value associated with the cell, empty string if cell's type is void/undefined
*/
@@ -96,7 +96,7 @@ class CellValueFormatter
/**
* Returns the cell String value.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @return string The value associated with the cell
*/
protected function formatStringCellValue($node)
@@ -115,7 +115,7 @@ class CellValueFormatter
}
/**
* @param $pNode
* @param \DOMNode $pNode
* @return string
*/
private function extractTextValueFromNode($pNode)
@@ -159,7 +159,7 @@ class CellValueFormatter
*
* @see https://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#__RefHeading__1415200_253892949
*
* @param \DOMNode $node The XML node representing a whitespace
* @param \DOMElement $node The XML node representing a whitespace
* @return string The corresponding whitespace value
*/
private function transformWhitespaceNode($node)
@@ -173,7 +173,7 @@ class CellValueFormatter
/**
* Returns the cell Numeric value from the given node.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @return int|float The value associated with the cell
*/
protected function formatFloatCellValue($node)
@@ -190,7 +190,7 @@ class CellValueFormatter
/**
* Returns the cell Boolean value from the given node.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @return bool The value associated with the cell
*/
protected function formatBooleanCellValue($node)
@@ -203,7 +203,7 @@ class CellValueFormatter
/**
* Returns the cell Date value from the given node.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @throws InvalidValueException If the value is not a valid date
* @return \DateTime|string The value associated with the cell
*/
@@ -234,7 +234,7 @@ class CellValueFormatter
/**
* Returns the cell Time value from the given node.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @throws InvalidValueException If the value is not a valid time
* @return \DateInterval|string The value associated with the cell
*/
@@ -265,7 +265,7 @@ class CellValueFormatter
/**
* Returns the cell Currency value from the given node.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @return string The value associated with the cell (e.g. "100 USD" or "9.99 EUR")
*/
protected function formatCurrencyCellValue($node)
@@ -279,7 +279,7 @@ class CellValueFormatter
/**
* Returns the cell Percentage value from the given node.
*
* @param \DOMNode $node
* @param \DOMElement $node
* @return int|float The value associated with the cell
*/
protected function formatPercentageCellValue($node)
+1 -1
View File
@@ -12,7 +12,7 @@ use Box\Spout\Reader\ReaderAbstract;
*/
class Reader extends ReaderAbstract
{
/** @var \ZipArchive */
/** @var \ZipArchive|null */
protected $zip;
/** @var SheetIterator To iterator over the ODS sheets */
+6 -4
View File
@@ -19,6 +19,7 @@ use Box\Spout\Reader\Wrapper\XMLReader;
/**
* Class RowIterator
* @implements IteratorInterface<Row>
*/
class RowIterator implements IteratorInterface
{
@@ -56,7 +57,7 @@ class RowIterator implements IteratorInterface
/** @var Row The currently processed row */
protected $currentlyProcessedRow;
/** @var Row Buffer used to store the current row, while checking if there are more rows to read */
/** @var Row|null Buffer used to store the current row, while checking if there are more rows to read */
protected $rowBuffer;
/** @var bool Indicates whether all rows have been read */
@@ -68,7 +69,7 @@ class RowIterator implements IteratorInterface
/** @var int Row index to be processed next (one-based) */
protected $nextRowIndexToBeProcessed = 1;
/** @var Cell Last processed cell (because when reading cell at column N+1, cell N is processed) */
/** @var Cell|null Last processed cell (because when reading cell at column N+1, cell N is processed) */
protected $lastProcessedCell;
/** @var int Number of times the last processed row should be repeated */
@@ -225,6 +226,7 @@ class RowIterator implements IteratorInterface
$currentNumColumnsRepeated = $this->getNumColumnsRepeatedForCurrentNode($xmlReader);
// NOTE: expand() will automatically decode all XML entities of the child nodes
/** @var \DOMElement $node */
$node = $xmlReader->expand();
$currentCell = $this->getCell($node);
@@ -316,7 +318,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)
@@ -339,7 +341,7 @@ class RowIterator implements IteratorInterface
* row data yet (as we still need to apply the "num-columns-repeated" attribute).
*
* @param Row $currentRow
* @param Cell $lastReadCell The last read cell
* @param Cell|null $lastReadCell The last read cell
* @return bool Whether the row is empty
*/
protected function isEmptyRow($currentRow, $lastReadCell)
+6 -4
View File
@@ -12,6 +12,7 @@ use Box\Spout\Reader\Wrapper\XMLReader;
/**
* Class SheetIterator
* Iterate over ODS sheet.
* @implements IteratorInterface<Sheet>
*/
class SheetIterator implements IteratorInterface
{
@@ -28,13 +29,13 @@ class SheetIterator implements IteratorInterface
const XML_ATTRIBUTE_TABLE_STYLE_NAME = 'table:style-name';
const XML_ATTRIBUTE_TABLE_DISPLAY = 'table:display';
/** @var string $filePath Path of the file to be read */
/** @var string Path of the file to be read */
protected $filePath;
/** @var \Box\Spout\Common\Manager\OptionsManagerInterface Reader's options manager */
protected $optionsManager;
/** @var InternalEntityFactory $entityFactory Factory to create entities */
/** @var InternalEntityFactory Factory to create entities */
protected $entityFactory;
/** @var XMLReader The XMLReader object that will help read sheet's XML data */
@@ -52,7 +53,7 @@ class SheetIterator implements IteratorInterface
/** @var string The name of the sheet that was defined as active */
protected $activeSheetName;
/** @var array Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE] */
/** @var array<string, bool> Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE] */
protected $sheetsVisibility;
/**
@@ -101,13 +102,14 @@ class SheetIterator implements IteratorInterface
/**
* Extracts the visibility of the sheets
*
* @return array Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE]
* @return array<string, bool> Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE]
*/
private function readSheetsVisibility()
{
$sheetsVisibility = [];
$this->xmlReader->readUntilNodeFound(self::XML_NODE_AUTOMATIC_STYLES);
/** @var \DOMElement $automaticStylesNode */
$automaticStylesNode = $this->xmlReader->expand();
$tableStyleNodes = $automaticStylesNode->getElementsByTagNameNS(self::XML_STYLE_NAMESPACE, self::XML_NODE_STYLE_TABLE_PROPERTIES);
+9 -5
View File
@@ -45,15 +45,15 @@ abstract class ReaderAbstract implements ReaderInterface
/**
* Returns an iterator to iterate over sheets.
*
* @return IteratorInterface To iterate over sheets
* @template T
* @return IteratorInterface<T>|null To iterate over sheets
*/
abstract protected function getConcreteSheetIterator();
/**
* Closes the reader. To be used after reading the file.
*
* @return ReaderAbstract
* @return void
*/
abstract protected function closeReader();
@@ -145,7 +145,10 @@ abstract class ReaderAbstract implements ReaderInterface
}
// Need to use realpath to fix "Can't open file" on some Windows setup
return \realpath($filePath);
/** @var string $path */
$path = \realpath($filePath);
return $path;
}
/**
@@ -211,7 +214,8 @@ abstract class ReaderAbstract implements ReaderInterface
* Returns an iterator to iterate over sheets.
*
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader
* @return \Iterator To iterate over sheets
* @template T
* @return IteratorInterface<T> To iterate over sheets
*/
public function getSheetIterator()
{
+1 -1
View File
@@ -21,7 +21,7 @@ interface ReaderInterface
* Returns an iterator to iterate over sheets.
*
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException If called before opening the reader
* @return \Iterator To iterate over sheets
* @return \Iterator<SheetInterface> To iterate over sheets
*/
public function getSheetIterator();
+3 -1
View File
@@ -2,13 +2,15 @@
namespace Box\Spout\Reader;
use Box\Spout\Common\Entity\Row;
/**
* Interface SheetInterface
*/
interface SheetInterface
{
/**
* @return IteratorInterface Iterator to iterate over the sheet's rows.
* @return IteratorInterface<Row> Iterator to iterate over the sheet's rows.
*/
public function getRowIterator();
@@ -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
{