diff --git a/src/PhpSpreadsheet/Cell/Cell.php b/src/PhpSpreadsheet/Cell/Cell.php index 08175fc1e..b53d1d1e0 100644 --- a/src/PhpSpreadsheet/Cell/Cell.php +++ b/src/PhpSpreadsheet/Cell/Cell.php @@ -464,6 +464,7 @@ class Cell implements Stringable } } } + /** @var string $newColumn */ ++$newColumn; } ++$newRow; @@ -502,6 +503,7 @@ class Cell implements Stringable $maxRow = (int) $matches[5]; for ($row = $minRow; $row <= $maxRow; ++$row) { for ($col = $minCol; $col !== $maxCol; ++$col) { + /** @var string $col */ if ("$col$row" !== $coordinate) { $thisworksheet->getCell("$col$row")->setValue(null); } @@ -524,8 +526,11 @@ class Cell implements Stringable $newColumn = $column; foreach ($resultRow as $resultValue) { if ($row !== $newRow || $column !== $newColumn) { - $thisworksheet->getCell($newColumn . $newRow)->setValue($resultValue); + $thisworksheet + ->getCell($newColumn . $newRow) + ->setValue($resultValue); } + /** @var string $newColumn */ ++$newColumn; } ++$newRow; @@ -934,9 +939,7 @@ class Cell implements Stringable /** * Set the formula attributes. * - * @param $attributes null|array - * - * @return $this + * @param null|array $attributes */ public function setFormulaAttributes(?array $attributes): self { diff --git a/src/PhpSpreadsheet/Cell/CellAddress.php b/src/PhpSpreadsheet/Cell/CellAddress.php index ab6258e66..a4a518e6a 100644 --- a/src/PhpSpreadsheet/Cell/CellAddress.php +++ b/src/PhpSpreadsheet/Cell/CellAddress.php @@ -48,6 +48,7 @@ class CellAddress implements Stringable return new self(Coordinate::stringFromColumnIndex($columnId) . $rowId, $worksheet); } + /** @param array $array */ public static function fromColumnRowArray(array $array, ?Worksheet $worksheet = null): self { [$columnId, $rowId] = $array; diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index c5d30838b..03c475fb6 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -170,13 +170,16 @@ abstract class Coordinate public static function buildRange(array $range): string { // Verify range - if (empty($range) || !is_array($range[0])) { + if (empty($range)) { throw new Exception('Range does not contain any information'); } // Build range $counter = count($range); for ($i = 0; $i < $counter; ++$i) { + if (!is_array($range[$i])) { + throw new Exception('Each array entry must be an array'); + } $range[$i] = implode(':', $range[$i]); } diff --git a/src/PhpSpreadsheet/Cell/RowRange.php b/src/PhpSpreadsheet/Cell/RowRange.php index 4ed232a93..1d35acc4c 100644 --- a/src/PhpSpreadsheet/Cell/RowRange.php +++ b/src/PhpSpreadsheet/Cell/RowRange.php @@ -27,6 +27,7 @@ class RowRange implements AddressRange, Stringable $this->worksheet = null; } + /** @param array{int, int} $array */ public static function fromArray(array $array, ?Worksheet $worksheet = null): self { [$from, $to] = $array; diff --git a/src/PhpSpreadsheet/Chart/DataSeriesValues.php b/src/PhpSpreadsheet/Chart/DataSeriesValues.php index 30ea79689..78a2bbec3 100644 --- a/src/PhpSpreadsheet/Chart/DataSeriesValues.php +++ b/src/PhpSpreadsheet/Chart/DataSeriesValues.php @@ -53,6 +53,8 @@ class DataSeriesValues extends Properties /** * Data Values. + * + * @var null|mixed[] */ private ?array $dataValues; @@ -75,6 +77,7 @@ class DataSeriesValues extends Properties /** * Create a new DataSeriesValues object. * + * @param null|mixed[] $dataValues * @param null|ChartColor|ChartColor[]|string|string[] $fillColor */ public function __construct( @@ -347,7 +350,10 @@ class DataSeriesValues extends Properties */ public function getLineWidth(): null|float|int { - return $this->lineStyleProperties['width']; + /** @var null|float|int */ + $temp = $this->lineStyleProperties['width']; + + return $temp; } /** @@ -381,6 +387,7 @@ class DataSeriesValues extends Properties { $levelCount = 0; foreach (($this->dataValues ?? []) as $dataValueSet) { + /** @var mixed[] $dataValueSet */ $levelCount = max($levelCount, count($dataValueSet)); } @@ -389,6 +396,8 @@ class DataSeriesValues extends Properties /** * Get Series Data Values. + * + * @return null|mixed[] */ public function getDataValues(): ?array { @@ -416,6 +425,8 @@ class DataSeriesValues extends Properties /** * Set Series Data Values. * + * @param mixed[] $dataValues + * * @return $this */ public function setDataValues(array $dataValues): static @@ -451,8 +462,9 @@ class DataSeriesValues extends Properties if (($dimensions[0] == 1) || ($dimensions[1] == 1)) { $this->dataValues = Functions::flattenArray($newDataValues); } else { - /** @var array */ + /** @var array */ $newDataValuesx = $newDataValues; + /** @var mixed[][] $newArray */ $newArray = array_values(array_shift($newDataValuesx) ?? []); foreach ($newArray as $i => $newDataSet) { $newArray[$i] = [$newDataSet]; @@ -467,7 +479,7 @@ class DataSeriesValues extends Properties $this->dataValues = $newArray; } } - $this->pointCount = count($this->dataValues); + $this->pointCount = count($this->dataValues ?? []); } } diff --git a/src/PhpSpreadsheet/Chart/Layout.php b/src/PhpSpreadsheet/Chart/Layout.php index 5dc2991a4..95e113d5e 100644 --- a/src/PhpSpreadsheet/Chart/Layout.php +++ b/src/PhpSpreadsheet/Chart/Layout.php @@ -101,9 +101,12 @@ class Layout /** * Create a new Layout. + * + * @param array $layout */ public function __construct(array $layout = []) { + /** @var array{layoutTarget?: string, xMode?: string, yMode?: string, x?: float, y?: float, w?:float, h?:float, dLblPos?: string, labelFont?: ?mixed, labelFontColor?: ?mixed, labelEffects?: ?mixed, numFmtCode?: string} $layout */ if (isset($layout['layoutTarget'])) { $this->layoutTarget = $layout['layoutTarget']; } @@ -155,6 +158,7 @@ class Layout } } + /** @param mixed[] $layout */ private function initBoolean(array $layout, string $name): void { if (isset($layout[$name])) { @@ -162,6 +166,7 @@ class Layout } } + /** @param mixed[] $layout */ private function initColor(array $layout, string $name): void { if (isset($layout[$name]) && $layout[$name] instanceof ChartColor) { diff --git a/src/PhpSpreadsheet/Chart/Properties.php b/src/PhpSpreadsheet/Chart/Properties.php index 64f97d53c..700ccd1d7 100644 --- a/src/PhpSpreadsheet/Chart/Properties.php +++ b/src/PhpSpreadsheet/Chart/Properties.php @@ -109,10 +109,12 @@ abstract class Properties protected ChartColor $glowColor; + /** @var array{size: ?float} */ protected array $softEdges = [ 'size' => null, ]; + /** @var mixed[] */ protected array $shadowProperties = self::PRESETS_OPTIONS[0]; protected ChartColor $shadowColor; @@ -395,6 +397,7 @@ abstract class Properties ], ]; + /** @return mixed[] */ protected function getShadowPresetsMap(int $presetsOption): array { return self::PRESETS_OPTIONS[$presetsOption] ?? self::PRESETS_OPTIONS[0]; @@ -402,6 +405,9 @@ abstract class Properties /** * Get value of array element. + * + * @param mixed[] $properties + * @param array|int|string $elements */ protected function getArrayElementsValue(array $properties, array|int|string $elements): mixed { @@ -411,7 +417,7 @@ abstract class Properties } foreach ($elements as $keys) { - $reference = &$reference[$keys]; + $reference = &$reference[$keys]; //* @phpstan-ignore-line } return $reference; @@ -436,6 +442,10 @@ abstract class Properties /** * Get Glow Property. + * + * @param mixed[]|string $property + * + * @return null|array|float|int|string */ public function getGlowProperty(array|string $property): null|array|float|int|string { @@ -449,7 +459,9 @@ abstract class Properties 'alpha' => $this->glowColor->getColorProperty('alpha'), ]; } elseif (is_array($property) && count($property) >= 2 && $property[0] === 'color') { - $retVal = $this->glowColor->getColorProperty($property[1]); + /** @var string */ + $temp = $property[1]; + $retVal = $this->glowColor->getColorProperty($temp); } return $retVal; @@ -566,6 +578,9 @@ abstract class Properties /** * Set Shadow Properties Values. * + * @param mixed[] $propertiesMap + * @param null|mixed[] $reference + * * @return $this */ protected function setShadowPropertiesMapValues(array $propertiesMap, ?array &$reference = null) @@ -574,8 +589,13 @@ abstract class Properties foreach ($propertiesMap as $property_key => $property_val) { if (is_array($property_val)) { if (in_array($property_key, self::SHADOW_ARRAY_KEYS, true)) { - $reference = &$this->shadowProperties[$property_key]; - $this->setShadowPropertiesMapValues($property_val, $reference); + /** @var null|array */ + $temp = &$this->shadowProperties[$property_key]; + $reference = &$temp; + $this->setShadowPropertiesMapValues( + $property_val, + $reference + ); } } else { if ($base_reference === null) { @@ -640,6 +660,8 @@ abstract class Properties * Get Shadow Property. * * @param string|string[] $elements + * + * @return null|mixed[]|string */ public function getShadowProperty($elements): array|string|null { @@ -662,6 +684,7 @@ abstract class Properties return $retVal; } + /** @return mixed[] */ public function getShadowArray(): array { $array = $this->shadowProperties; @@ -674,6 +697,7 @@ abstract class Properties protected ChartColor $lineColor; + /** @var array{width: null|float|int|string, compound: ?string, dash: ?string, cap: ?string, join: ?string, arrow: array{head: array{type: ?string, size: null|int|string, w: ?string, len: ?string}, end: array{type: ?string, size: null|int|string, w: ?string, len: ?string}}} */ protected array $lineStyleProperties = [ 'width' => null, //'9525', 'compound' => '', //self::LINE_STYLE_COMPOUND_SIMPLE, @@ -798,13 +822,16 @@ abstract class Properties } } + /** @return mixed[] */ public function getLineStyleArray(): array { return $this->lineStyleProperties; } + /** @param mixed[] $lineStyleProperties */ public function setLineStyleArray(array $lineStyleProperties = []): self { + /** @var array{width?: ?string, compound?: string, dash?: string, cap?: string, join?: string, arrow?: array{head?: array{type?: string, size?: int, w?: string, len?: string}, end?: array{type?: string, size?: int, w?: string, len?: string}}} $lineStyleProperties */ $this->activateObject(); $this->lineStyleProperties['width'] = $lineStyleProperties['width'] ?? null; $this->lineStyleProperties['compound'] = $lineStyleProperties['compound'] ?? ''; @@ -826,13 +853,15 @@ abstract class Properties public function setLineStyleProperty(string $propertyName, mixed $value): self { $this->activateObject(); - $this->lineStyleProperties[$propertyName] = $value; + $this->lineStyleProperties[$propertyName] = $value; //* @phpstan-ignore-line return $this; } /** * Get Line Style Property. + * + * @param array|string $elements */ public function getLineStyleProperty(array|string $elements): ?string { @@ -873,7 +902,7 @@ abstract class Properties */ public function getLineStyleArrowParameters(string $arrowSelector, string $propertySelector): string { - return $this->getLineStyleArrowSize($this->lineStyleProperties['arrow'][$arrowSelector]['size'], $propertySelector); + return $this->getLineStyleArrowSize((int) $this->lineStyleProperties['arrow'][$arrowSelector]['size'], $propertySelector); } /** diff --git a/src/PhpSpreadsheet/Chart/Title.php b/src/PhpSpreadsheet/Chart/Title.php index 461a2e851..adbb731d5 100644 --- a/src/PhpSpreadsheet/Chart/Title.php +++ b/src/PhpSpreadsheet/Chart/Title.php @@ -36,6 +36,8 @@ class Title /** * Create a new Title. + * + * @param array|RichText|string $caption */ public function __construct(array|RichText|string $caption = '', ?Layout $layout = null, bool $overlay = false) { @@ -86,6 +88,8 @@ class Title /** * Set caption. * + * @param array|RichText|string $caption + * * @return $this */ public function setCaption(array|RichText|string $caption): static @@ -161,11 +165,11 @@ class Title $this->layout = ($this->layout === null) ? null : clone $this->layout; $this->font = ($this->font === null) ? null : clone $this->font; if (is_array($this->caption)) { - $captions = $this->caption; - $this->caption = []; - foreach ($captions as $caption) { - $this->caption[] = is_object($caption) ? (clone $caption) : $caption; + $captions = []; + foreach ($this->caption as $caption) { + $captions[] = is_object($caption) ? (clone $caption) : $caption; } + $this->caption = $captions; } else { $this->caption = is_object($this->caption) ? (clone $this->caption) : $this->caption; } diff --git a/src/PhpSpreadsheet/Collection/Cells.php b/src/PhpSpreadsheet/Collection/Cells.php index 76bbc3222..365c37e89 100644 --- a/src/PhpSpreadsheet/Collection/Cells.php +++ b/src/PhpSpreadsheet/Collection/Cells.php @@ -185,7 +185,7 @@ class Cells /** * Get highest worksheet column and highest row that have cell records. * - * @return array Highest column name and highest row number + * @return array{row: int, column: string} Highest column name and highest row number */ public function getHighestRowAndColumn(): array { @@ -387,6 +387,7 @@ class Cells $column = 0; $row = ''; sscanf($cellCoordinate, '%[A-Z]%d', $column, $row); + /** @var int $row */ $this->index[$cellCoordinate] = (--$row * self::MAX_COLUMN_ID) + Coordinate::columnIndexFromString((string) $column); $this->currentCoordinate = $cellCoordinate; diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 178f73bcc..b13114ab4 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -813,7 +813,6 @@ class Xlsx extends BaseReader $xmlSheetMain = $xmlSheetNS->children($mainNS); // Setting Conditional Styles adjusts selected cells, so we need to execute this // before reading the sheet view data to get the actual selected cells - /** @var Style[] $dxfs */ if (!$this->readDataOnly && ($xmlSheet->conditionalFormatting)) { (new ConditionalStyles($docSheet, $xmlSheet, $dxfs, $this->styleReader))->load(); } @@ -1936,6 +1935,7 @@ class Xlsx extends BaseReader } } + /** @var array|string>>> $unparsedLoadedData */ $excel->setUnparsedLoadedData($unparsedLoadedData); $zip->close(); @@ -2345,7 +2345,7 @@ class Xlsx extends BaseReader /** * @param TableDxfsStyle[] $tableStyles - * @param mixed[] $dxfs + * @param Style[] $dxfs */ private function readTables( SimpleXMLElement $xmlSheet, @@ -2368,7 +2368,7 @@ class Xlsx extends BaseReader /** * @param TableDxfsStyle[] $tableStyles - * @param mixed[] $dxfs + * @param Style[] $dxfs */ private function readTablesInTablesFile( SimpleXMLElement $xmlSheet, diff --git a/src/PhpSpreadsheet/Reader/Xlsx/Styles.php b/src/PhpSpreadsheet/Reader/Xlsx/Styles.php index 0c2151720..7dce244db 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx/Styles.php +++ b/src/PhpSpreadsheet/Reader/Xlsx/Styles.php @@ -427,7 +427,7 @@ class Styles extends BaseParserClass return ($background) ? 'FFFFFFFF' : 'FF000000'; } - /** @return mixed[] */ + /** @return Style[] */ public function dxfs(bool $readDataOnly = false): array { $dxfs = []; diff --git a/src/PhpSpreadsheet/Reader/Xlsx/TableReader.php b/src/PhpSpreadsheet/Reader/Xlsx/TableReader.php index c82195866..121697cc2 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx/TableReader.php +++ b/src/PhpSpreadsheet/Reader/Xlsx/TableReader.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xlsx; +use PhpOffice\PhpSpreadsheet\Style\Style; use PhpOffice\PhpSpreadsheet\Worksheet\Table; use PhpOffice\PhpSpreadsheet\Worksheet\Table\TableDxfsStyle; use PhpOffice\PhpSpreadsheet\Worksheet\Table\TableStyle; @@ -27,7 +28,7 @@ class TableReader * Loads Table into the Worksheet. * * @param TableDxfsStyle[] $tableStyles - * @param mixed[] $dxfs + * @param Style[] $dxfs */ public function load(array $tableStyles, array $dxfs): void { @@ -43,7 +44,7 @@ class TableReader * Read Table from xml. * * @param TableDxfsStyle[] $tableStyles - * @param mixed[] $dxfs + * @param Style[] $dxfs */ private function readTable(string $tableRange, array $tableStyles, array $dxfs): void { @@ -112,7 +113,7 @@ class TableReader * Reads TableStyle from xml. * * @param TableDxfsStyle[] $tableStyles - * @param mixed[] $dxfs + * @param Style[] $dxfs */ private function readTableStyle(Table $table, SimpleXMLElement $tableStyleInfoXml, array $tableStyles, array $dxfs): void { diff --git a/src/PhpSpreadsheet/ReferenceHelper.php b/src/PhpSpreadsheet/ReferenceHelper.php index 24ae60e86..bfafc971b 100644 --- a/src/PhpSpreadsheet/ReferenceHelper.php +++ b/src/PhpSpreadsheet/ReferenceHelper.php @@ -451,6 +451,7 @@ class ReferenceHelper $highColumn = Coordinate::columnIndexFromString($highestDataColumn); for ($row = $startRow; $row <= $highestDataRow; ++$row) { for ($col = $startCol, $colString = $startColString; $col <= $highColumn; ++$col, ++$colString) { + /** @var string $colString */ $worksheet->getCell("$colString$row"); // create cell if it doesn't exist } } @@ -1041,6 +1042,7 @@ class ReferenceHelper for ($row = 1; $row <= $highestRow - 1; ++$row) { for ($column = $startColumnId; $column !== $endColumnId; ++$column) { + /** @var string $column */ $coordinate = $column . $row; $this->clearStripCell($worksheet, $coordinate); } @@ -1053,6 +1055,7 @@ class ReferenceHelper ++$highestColumn; for ($column = $startColumnId; $column !== $highestColumn; ++$column) { + /** @var string $column */ for ($row = $beforeRow + $numberOfRows; $row <= $beforeRow - 1; ++$row) { $coordinate = $column . $row; $this->clearStripCell($worksheet, $coordinate); @@ -1108,6 +1111,7 @@ class ReferenceHelper } } + /** @param mixed[] $autoFilterColumns */ private function adjustAutoFilterDeleteRules(int $columnIndex, int $numberOfColumns, array $autoFilterColumns, AutoFilter $autoFilter): void { // If we're actually deleting any columns that fall within the autofilter range, @@ -1146,9 +1150,11 @@ class ReferenceHelper do { $autoFilter->shiftColumn($startColID, $toColID); + /** @var string $toColID */ ++$toColID; - ++$startColID; // this confuses phpstan into thinking startColID is int/float - } while ($startColID !== $endColID); // @phpstan-ignore-line + /** @var string $startColID */ + ++$startColID; + } while ($startColID !== $endColID); } private function adjustTable(Worksheet $worksheet, string $beforeCellAddress, int $numberOfColumns): void @@ -1187,6 +1193,7 @@ class ReferenceHelper } } + /** @param mixed[] $tableColumns */ private function adjustTableDeleteRules(int $columnIndex, int $numberOfColumns, array $tableColumns, Table $table): void { // If we're actually deleting any columns that fall within the table range, @@ -1225,9 +1232,11 @@ class ReferenceHelper do { $table->shiftColumn($startColID, $toColID); + /** @var string $toColID */ ++$toColID; - ++$startColID; // this confuses phpstan into thinking startColID is int/float - } while ($startColID !== $endColID); // @phpstan-ignore-line + /** @var string $startColID */ + ++$startColID; + } while ($startColID !== $endColID); } private function duplicateStylesByColumn(Worksheet $worksheet, int $beforeColumn, int $beforeRow, int $highestRow, int $numberOfColumns): void diff --git a/src/PhpSpreadsheet/Shared/CodePage.php b/src/PhpSpreadsheet/Shared/CodePage.php index ddc9def89..de6529c5c 100644 --- a/src/PhpSpreadsheet/Shared/CodePage.php +++ b/src/PhpSpreadsheet/Shared/CodePage.php @@ -107,6 +107,7 @@ class CodePage throw new PhpSpreadsheetException('Unknown codepage: ' . $codePage); } + /** @return array|string> */ public static function getEncodings(): array { return self::$pageArray; diff --git a/src/PhpSpreadsheet/Shared/Font.php b/src/PhpSpreadsheet/Shared/Font.php index f9370b4e1..27490e388 100644 --- a/src/PhpSpreadsheet/Shared/Font.php +++ b/src/PhpSpreadsheet/Shared/Font.php @@ -436,6 +436,7 @@ class Font } // Get corners positions + /** @var int[] $textBox */ $lowerLeftCornerX = $textBox[0]; $lowerRightCornerX = $textBox[2]; $upperRightCornerX = $textBox[4]; diff --git a/src/PhpSpreadsheet/Shared/StringHelper.php b/src/PhpSpreadsheet/Shared/StringHelper.php index 4427028a3..40adfd8c9 100644 --- a/src/PhpSpreadsheet/Shared/StringHelper.php +++ b/src/PhpSpreadsheet/Shared/StringHelper.php @@ -17,6 +17,8 @@ class StringHelper /** * SYLK Characters array. + * + * @var string[] */ private static array $SYLKCharacters = []; @@ -485,6 +487,8 @@ class StringHelper /** * Splits a UTF-8 string into an array of individual characters. + * + * @return string[] */ public static function mbStrSplit(string $string): array { @@ -522,6 +526,7 @@ class StringHelper private static function getLocaleValue(string $key, string $altKey, string $default, bool $trimAlt = false): string { + /** @var string[] */ $localeconv = localeconv(); $rslt = $localeconv[$key]; // win-1252 implements Euro as 0x80 plus other symbols diff --git a/src/PhpSpreadsheet/Shared/Xls.php b/src/PhpSpreadsheet/Shared/Xls.php index cdb1bf243..6e34a5de8 100644 --- a/src/PhpSpreadsheet/Shared/Xls.php +++ b/src/PhpSpreadsheet/Shared/Xls.php @@ -201,6 +201,8 @@ class Xls * @param int $offsetY Vertical offset in pixels * @param int $width Width in pixels * @param int $height Height in pixels + * + * @return array{startCoordinates: string, startOffsetX: int, startOffsetY: int, endCoordinates: string, endOffsetX: int, endOffsetY: int} */ public static function oneAnchor2twoAnchor(Worksheet $worksheet, string $coordinates, int $offsetX, int $offsetY, int $width, int $height): ?array { diff --git a/src/PhpSpreadsheet/Spreadsheet.php b/src/PhpSpreadsheet/Spreadsheet.php index 13d450aa9..09022bbc6 100644 --- a/src/PhpSpreadsheet/Spreadsheet.php +++ b/src/PhpSpreadsheet/Spreadsheet.php @@ -115,12 +115,16 @@ class Spreadsheet implements JsonSerializable /** * ribbonBinObjects : null if workbook is'nt Excel 2007 or not contain embedded objects (picture(s)) for Ribbon Elements * ignored if $ribbonXMLData is null. + * + * @var null|mixed[] */ private ?array $ribbonBinObjects = null; /** * List of unparsed loaded data for export to same format with better compatibility. * It has to be minimized when the library start to support currently unparsed data. + * + * @var array|string>>> */ private array $unparsedLoadedData = []; @@ -263,6 +267,8 @@ class Spreadsheet implements JsonSerializable /** * retrieve ribbon XML Data. + * + * @return mixed[] */ public function getRibbonXMLData(string $what = 'all'): null|array|string //we need some constants here... { @@ -302,6 +308,8 @@ class Spreadsheet implements JsonSerializable * It has to be minimized when the library start to support currently unparsed data. * * @internal + * + * @return mixed[] */ public function getUnparsedLoadedData(): array { @@ -313,6 +321,8 @@ class Spreadsheet implements JsonSerializable * It has to be minimized when the library start to support currently unparsed data. * * @internal + * + * @param array|string>>> $unparsedLoadedData */ public function setUnparsedLoadedData(array $unparsedLoadedData): void { @@ -321,6 +331,8 @@ class Spreadsheet implements JsonSerializable /** * retrieve Binaries Ribbon Objects. + * + * @return mixed[] */ public function getRibbonBinObjects(string $what = 'all'): ?array { @@ -1676,7 +1688,10 @@ class Spreadsheet implements JsonSerializable public function getLegacyDrawing(Worksheet $worksheet): ?string { - return $this->unparsedLoadedData['sheets'][$worksheet->getCodeName()]['legacyDrawing'] ?? null; + /** @var ?string */ + $temp = $this->unparsedLoadedData['sheets'][$worksheet->getCodeName()]['legacyDrawing'] ?? null; + + return $temp; } public function getValueBinder(): ?IValueBinder diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter.php b/src/PhpSpreadsheet/Worksheet/AutoFilter.php index 5747d77c5..9074288a2 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter.php @@ -368,11 +368,10 @@ class AutoFilter implements Stringable /** * Test if cell value is within a set of values defined by a ruleset. * - * @param mixed[] $ruleSet + * @param mixed[][] $ruleSet */ protected static function filterTestInCustomDataSet(mixed $cellValue, array $ruleSet): bool { - /** @var array[] $dataSet */ $dataSet = $ruleSet['filterRules']; $join = $ruleSet['join']; $customRuleForBlanks = $ruleSet['customRuleForBlanks'] ?? false; @@ -385,11 +384,10 @@ class AutoFilter implements Stringable } $returnVal = ($join == AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_AND); foreach ($dataSet as $rule) { - /** @var string $ruleValue */ + /** @var string[] $rule */ $ruleValue = $rule['value']; - /** @var string $ruleOperator */ $ruleOperator = $rule['operator']; - /** @var string $cellValueString */ + /** @var string */ $cellValueString = $cellValue ?? ''; $retVal = false; @@ -529,6 +527,7 @@ class AutoFilter implements Stringable Rule::AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY => 'dynamicYesterday', ]; + /** @return array{DateTime, DateTime} */ private static function dynamicLastMonth(): array { $maxval = new DateTime(); @@ -554,6 +553,7 @@ class AutoFilter implements Stringable return $val; } + /** @return array{DateTime, DateTime} */ private static function dynamicLastQuarter(): array { $maxval = self::firstDayOfQuarter(); @@ -563,6 +563,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicLastWeek(): array { $val = new DateTime(); @@ -576,6 +577,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicLastYear(): array { $val = new DateTime(); @@ -586,6 +588,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicNextMonth(): array { $val = new DateTime(); @@ -600,6 +603,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicNextQuarter(): array { $val = self::firstDayOfQuarter(); @@ -610,6 +614,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicNextWeek(): array { $val = new DateTime(); @@ -623,6 +628,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicNextYear(): array { $val = new DateTime(); @@ -633,6 +639,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicThisMonth(): array { $baseDate = new DateTime(); @@ -646,6 +653,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicThisQuarter(): array { $val = self::firstDayOfQuarter(); @@ -655,6 +663,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicThisWeek(): array { $val = new DateTime(); @@ -668,6 +677,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicThisYear(): array { $val = new DateTime(); @@ -678,6 +688,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicToday(): array { $val = new DateTime(); @@ -688,6 +699,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicTomorrow(): array { $val = new DateTime(); @@ -699,6 +711,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicYearToDate(): array { $maxval = new DateTime(); @@ -709,6 +722,7 @@ class AutoFilter implements Stringable return [$val, $maxval]; } + /** @return array{DateTime, DateTime} */ private static function dynamicYesterday(): array { $maxval = new DateTime(); @@ -941,6 +955,7 @@ class AutoFilter implements Stringable if ($periodType == 'M') { $ruleValues = [$period]; } else { + /** @var int $period */ --$period; $periodEnd = (1 + $period) * 3; $periodStart = 1 + $period * 3; diff --git a/src/PhpSpreadsheet/Worksheet/AutoFit.php b/src/PhpSpreadsheet/Worksheet/AutoFit.php index 859a70fc6..b4bd1b17e 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFit.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFit.php @@ -15,13 +15,13 @@ class AutoFit $this->worksheet = $worksheet; } + /** @return mixed[] */ public function getAutoFilterIndentRanges(): array { $autoFilterIndentRanges = []; $autoFilterIndentRanges[] = $this->getAutoFilterIndentRange($this->worksheet->getAutoFilter()); foreach ($this->worksheet->getTableCollection() as $table) { - /** @var Table $table */ if ($table->getShowHeaderRow() === true && $table->getAllowFilter() === true) { $autoFilter = $table->getAutoFilter(); $autoFilterIndentRanges[] = $this->getAutoFilterIndentRange($autoFilter); diff --git a/src/PhpSpreadsheet/Worksheet/Table/TableStyle.php b/src/PhpSpreadsheet/Worksheet/Table/TableStyle.php index 2c0173c19..bb92e1b68 100644 --- a/src/PhpSpreadsheet/Worksheet/Table/TableStyle.php +++ b/src/PhpSpreadsheet/Worksheet/Table/TableStyle.php @@ -2,6 +2,7 @@ namespace PhpOffice\PhpSpreadsheet\Worksheet\Table; +use PhpOffice\PhpSpreadsheet\Style\Style; use PhpOffice\PhpSpreadsheet\Worksheet\Table; class TableStyle @@ -213,6 +214,8 @@ class TableStyle /** * Set this Style's Dxfs TableStyle. + * + * @param Style[] $dxfs */ public function setTableDxfsStyle(TableDxfsStyle $tableStyle, array $dxfs): self { diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index e9e0d78c6..38faec617 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -287,12 +287,16 @@ class Worksheet /** * Hyperlinks. Indexed by cell coordinate, e.g. 'A1'. + * + * @var Hyperlink[] */ private array $hyperlinkCollection = []; /** * Data validation objects. Indexed by cell coordinate, e.g. 'A1'. * Index can include ranges, and multiple cells/ranges. + * + * @var DataValidation[] */ private array $dataValidationCollection = []; @@ -389,6 +393,8 @@ class Worksheet /** * Get array of invalid characters for sheet title. + * + * @return string[] */ public static function getInvalidCharacters(): array { @@ -729,6 +735,7 @@ class Worksheet $filterAdjustment = false; if (!empty($autoFilterIndentRanges)) { foreach ($autoFilterIndentRanges as $autoFilterFirstRowRange) { + /** @var string $autoFilterFirstRowRange */ if ($cell->isInRange($autoFilterFirstRowRange)) { $filterAdjustment = true; @@ -1101,7 +1108,7 @@ class Worksheet /** * Get highest worksheet column and highest row that have cell records. * - * @return array Highest column name and highest row number + * @return array{row: int, column: string} Highest column name and highest row number */ public function getHighestRowAndColumn(): array { @@ -1421,6 +1428,8 @@ class Worksheet * * @param Cell $cell * The Cell for which the tables are retrieved + * + * @return mixed[] */ public function getTablesWithStylesForCell(Cell $cell): array { @@ -1861,6 +1870,11 @@ class Worksheet } } + /** + * @param mixed[] $leftCellValue + * + * @return mixed[] + */ public function mergeCellBehaviour(Cell $cell, string $upperLeft, string $behaviour, array $leftCellValue): array { if ($cell->getCoordinate() !== $upperLeft) { @@ -2416,6 +2430,7 @@ class Worksheet return $this; } + /** @return RowDimension[] */ private function removeRowDimensions(int $row, int $numberOfRows): array { $highRow = $row + $numberOfRows - 1; @@ -2477,6 +2492,7 @@ class Worksheet return $this; } + /** @return ColumnDimension[] */ private function removeColumnDimensions(int $pColumnIndex, int $numberOfColumns): array { $highCol = $pColumnIndex + $numberOfColumns - 1; @@ -2809,7 +2825,7 @@ class Worksheet /** * Fill worksheet from values in array. * - * @param array $source Source array + * @param mixed[]|mixed[][] $source Source array * @param mixed $nullValue Value in source array that stands for blank cell * @param string $startCell Insert array starting from this cell address as the top left coordinate * @param bool $strictNullComparison Apply strict comparison when testing for null values in the array @@ -2822,19 +2838,23 @@ class Worksheet if (!is_array(end($source))) { $source = [$source]; } + /** @var mixed[][] $source */ // start coordinate [$startColumn, $startRow] = Coordinate::coordinateFromString($startCell); + $startRow = (int) $startRow; // Loop through $source if ($strictNullComparison) { foreach ($source as $rowData) { + /** @var string */ $currentColumn = $startColumn; foreach ($rowData as $cellValue) { if ($cellValue !== $nullValue) { - // Set cell value + /** @var string $currentColumn */ $this->getCell($currentColumn . $startRow)->setValue($cellValue); } + /** @var string $currentColumn */ ++$currentColumn; } ++$startRow; @@ -2844,9 +2864,10 @@ class Worksheet $currentColumn = $startColumn; foreach ($rowData as $cellValue) { if ($cellValue != $nullValue) { - // Set cell value + /** @var string $currentColumn */ $this->getCell($currentColumn . $startRow)->setValue($cellValue); } + /** @var string $currentColumn */ ++$currentColumn; } ++$startRow; @@ -2930,6 +2951,8 @@ class Worksheet * True - Return rows and columns indexed by their actual row and column IDs * @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden. * True - Don't return values for rows/columns that are defined as hidden. + * + * @return mixed[][] */ public function rangesToArray( string $ranges, @@ -2965,7 +2988,7 @@ class Worksheet * @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden. * True - Don't return values for rows/columns that are defined as hidden. * - * @return Generator + * @return Generator> */ public function rangeToArrayYieldRows( string $range, @@ -3049,6 +3072,8 @@ class Worksheet * @param bool $ignoreHidden False - Return values for rows/columns even if they are defined as hidden. * True - Don't return values for rows/columns that are defined as hidden. * @param array $hiddenColumns + * + * @return mixed[] */ private function buildNullRow( mixed $nullValue, @@ -3061,8 +3086,9 @@ class Worksheet $nullRow = []; $c = -1; for ($col = $minCol; $col !== $maxCol; ++$col) { + /** @var string $col */ if ($ignoreHidden === true && $this->columnDimensionExists($col) && $this->getColumnDimension($col)->getVisible() === false) { - $hiddenColumns[$col] = true; // @phpstan-ignore-line + $hiddenColumns[$col] = true; } else { $columnRef = $returnCellRef ? $col : ++$c; $nullRow[$columnRef] = $nullValue; @@ -3230,6 +3256,7 @@ class Worksheet } else { $this->cachedHighestColumn = $highestColumn; } + /** @var int $highestRow */ $this->cachedHighestRow = $highestRow; // Return diff --git a/tests/PhpSpreadsheetTests/Calculation/InternalFunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/InternalFunctionsTest.php index 0175e7b78..d81d52433 100644 --- a/tests/PhpSpreadsheetTests/Calculation/InternalFunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/InternalFunctionsTest.php @@ -6,11 +6,13 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class InternalFunctionsTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('anchorArrayDataProvider')] + /** @param mixed[] $expectedResult */ + #[DataProvider('anchorArrayDataProvider')] public function testAnchorArrayFormula(string $reference, string $range, array $expectedResult): void { $spreadsheet = new Spreadsheet(); @@ -49,7 +51,7 @@ class InternalFunctionsTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('singleDataProvider')] + #[DataProvider('singleDataProvider')] public function testSingleArrayFormula(string $reference, mixed $expectedResult): void { $spreadsheet = new Spreadsheet(); diff --git a/tests/PhpSpreadsheetTests/Calculation/ParseFormulaTest.php b/tests/PhpSpreadsheetTests/Calculation/ParseFormulaTest.php index c529700ee..22f57b31f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/ParseFormulaTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/ParseFormulaTest.php @@ -8,11 +8,13 @@ use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engine\Operands\StructuredReference; use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ParseFormulaTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('providerBinaryOperations')] + /** @param mixed[] $expectedStack */ + #[DataProvider('providerBinaryOperations')] public function testParseOperations(array $expectedStack, string $formula): void { $spreadsheet = new Spreadsheet(); diff --git a/tests/PhpSpreadsheetTests/Cell/CellAddressTest.php b/tests/PhpSpreadsheetTests/Cell/CellAddressTest.php index e0e030e8e..a974a78af 100644 --- a/tests/PhpSpreadsheetTests/Cell/CellAddressTest.php +++ b/tests/PhpSpreadsheetTests/Cell/CellAddressTest.php @@ -7,11 +7,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Cell; use PhpOffice\PhpSpreadsheet\Cell\CellAddress; use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class CellAddressTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateFromCellAddress')] + #[DataProvider('providerCreateFromCellAddress')] public function testCreateFromCellAddress( string $cellAddress, string $expectedColumnName, @@ -36,7 +37,7 @@ class CellAddressTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateFromCellAddressException')] + #[DataProvider('providerCreateFromCellAddressException')] public function testCreateFromCellAddressException(string $cellAddress): void { $this->expectException(Exception::class); @@ -59,7 +60,7 @@ class CellAddressTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateFromColumnAndRow')] + #[DataProvider('providerCreateFromColumnAndRow')] public function testCreateFromColumnAndRow( int $columnId, int $rowId, @@ -75,7 +76,7 @@ class CellAddressTest extends TestCase self::assertSame($expectedColumnName, $cellAddressObject->columnName()); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateFromColumnRowException')] + #[DataProvider('providerCreateFromColumnRowException')] public function testCreateFromColumnRowException(int|string $columnId, int|string $rowId): void { $this->expectException(Exception::class); @@ -93,7 +94,7 @@ class CellAddressTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateFromColumnRowArray')] + #[DataProvider('providerCreateFromColumnRowArray')] public function testCreateFromColumnRowArray( int $columnId, int $rowId, @@ -119,14 +120,15 @@ class CellAddressTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateFromColumnRowException')] + #[DataProvider('providerCreateFromColumnRowException')] public function testCreateFromColumnRowArrayException(mixed $columnId, mixed $rowId): void { $this->expectException(Exception::class); $this->expectExceptionMessage('Row and Column Ids must be positive integer values'); $columnRowArray = [$columnId, $rowId]; - CellAddress::fromColumnRowArray($columnRowArray); + // Phpstan is right to complain about next line, but we need to test it anyhow + CellAddress::fromColumnRowArray($columnRowArray); //* @phpstan-ignore-line } public static function providerCreateFromColumnRowException(): array @@ -137,7 +139,7 @@ class CellAddressTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateFromCellAddressWithWorksheet')] + #[DataProvider('providerCreateFromCellAddressWithWorksheet')] public function testCreateFromCellAddressWithWorksheet( string $cellAddress, string $expectedCellAddress, diff --git a/tests/PhpSpreadsheetTests/Cell/CellTest.php b/tests/PhpSpreadsheetTests/Cell/CellTest.php index f3539c607..9b0ba5572 100644 --- a/tests/PhpSpreadsheetTests/Cell/CellTest.php +++ b/tests/PhpSpreadsheetTests/Cell/CellTest.php @@ -15,6 +15,7 @@ use PhpOffice\PhpSpreadsheet\Style\Color; use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard; use PhpOffice\PhpSpreadsheet\Style\Fill; use PhpOffice\PhpSpreadsheet\Style\Style; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class CellTest extends TestCase @@ -76,7 +77,7 @@ class CellTest extends TestCase $spreadsheet->disconnectWorksheets(); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerSetValueExplicit')] + #[DataProvider('providerSetValueExplicit')] public function testSetValueExplicit(mixed $expected, mixed $value, string $dataType): void { $spreadsheet = new Spreadsheet(); @@ -103,7 +104,7 @@ class CellTest extends TestCase $cell->setValueExplicit($dateValue, DataType::TYPE_ISO_DATE); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerSetValueExplicitException')] + #[DataProvider('providerSetValueExplicitException')] public function testSetValueExplicitException(mixed $value, string $dataType): void { $this->expectException(Exception::class); @@ -246,7 +247,7 @@ class CellTest extends TestCase $spreadsheet->disconnectWorksheets(); } - #[\PHPUnit\Framework\Attributes\DataProvider('appliedStyling')] + #[DataProvider('appliedStylingProvider')] public function testAppliedStyleSingleCell(string $cellAddress, string $fillStyle, ?string $fillColor): void { $spreadsheet = new Spreadsheet(); @@ -296,7 +297,7 @@ class CellTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function appliedStyling(): array + public static function appliedStylingProvider(): array { return [ 'A1 - Conditional with Match' => ['A1', Fill::FILL_SOLID, Color::COLOR_RED], diff --git a/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php b/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php index ddaf16d89..c56e6d3d9 100644 --- a/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php +++ b/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php @@ -91,6 +91,7 @@ class ComplexAssert extends TestCase return $this->errorMessage; } + /** @param array|float|string $actual */ public function runAssertComplexEquals(string $expected, array|float|string $actual, ?float $delta = null): void { self::assertTrue($this->assertComplexEquals($expected, $actual, $delta), $this->getErrorMessage()); diff --git a/tests/PhpSpreadsheetTests/DefinedNameFormulaTest.php b/tests/PhpSpreadsheetTests/DefinedNameFormulaTest.php index 4117c4745..d962122e0 100644 --- a/tests/PhpSpreadsheetTests/DefinedNameFormulaTest.php +++ b/tests/PhpSpreadsheetTests/DefinedNameFormulaTest.php @@ -7,11 +7,12 @@ namespace PhpOffice\PhpSpreadsheetTests; use PhpOffice\PhpSpreadsheet\DefinedName; use PhpOffice\PhpSpreadsheet\NamedFormula; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class DefinedNameFormulaTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('providerRangeOrFormula')] + #[DataProvider('providerRangeOrFormula')] public function testRangeOrFormula(string $value, bool $expectedResult): void { $actualResult = DefinedName::testIfFormula($value); @@ -25,9 +26,13 @@ class DefinedNameFormulaTest extends TestCase $definedNamesForTest = $this->providerRangeOrFormula(); foreach ($definedNamesForTest as $key => $definedNameData) { + /** @var array{string, bool} $definedNameData */ [$value] = $definedNameData; $name = str_replace([' ', '-'], '_', $key); - $spreadSheet->addDefinedName(DefinedName::createInstance($name, $workSheet, $value)); + $spreadSheet + ->addDefinedName( + DefinedName::createInstance($name, $workSheet, $value) + ); } $allDefinedNames = $spreadSheet->getDefinedNames(); @@ -42,6 +47,7 @@ class DefinedNameFormulaTest extends TestCase $rangeOrFormula = []; $definedNamesForTest = $this->providerRangeOrFormula(); foreach ($definedNamesForTest as $key => $definedNameData) { + /** @var array{string, bool} $definedNameData */ [$value, $isFormula] = $definedNameData; $rangeOrFormula[] = !$isFormula; $name = str_replace([' ', '-'], '_', $key); @@ -96,6 +102,7 @@ class DefinedNameFormulaTest extends TestCase $rangeOrFormula = []; $definedNamesForTest = $this->providerRangeOrFormula(); foreach ($definedNamesForTest as $key => $definedNameData) { + /** @var array{string, bool} $definedNameData */ [$value, $isFormula] = $definedNameData; $rangeOrFormula[] = $isFormula; $name = str_replace([' ', '-'], '_', $key); diff --git a/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php b/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php index e4bc37574..8c467db9b 100644 --- a/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php +++ b/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php @@ -19,6 +19,7 @@ class DocumentGeneratorTest extends TestCase private static bool $succeededByCategory = false; + /** @param array|string, argumentCount: string, passCellReference?: bool, passByReference?: array, custom?: bool}> $phpSpreadsheetFunctions */ #[DataProvider('providerGenerateFunctionListByName')] public function testGenerateFunctionListByName(array $phpSpreadsheetFunctions, string $expected): void { @@ -26,6 +27,7 @@ class DocumentGeneratorTest extends TestCase self::$succeededByName = true; } + /** @param array|string, argumentCount: string, passCellReference?: bool, passByReference?: array, custom?: bool}> $phpSpreadsheetFunctions */ #[DataProvider('providerGenerateFunctionListByCategory')] public function testGenerateFunctionListByCategory(array $phpSpreadsheetFunctions, string $expected): void { diff --git a/tests/PhpSpreadsheetTests/Functional/ReadFilterTest.php b/tests/PhpSpreadsheetTests/Functional/ReadFilterTest.php index 9b4920d84..fd95a3137 100644 --- a/tests/PhpSpreadsheetTests/Functional/ReadFilterTest.php +++ b/tests/PhpSpreadsheetTests/Functional/ReadFilterTest.php @@ -6,6 +6,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Functional; use PhpOffice\PhpSpreadsheet\Reader\IReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PHPUnit\Framework\Attributes\DataProvider; class ReadFilterTest extends AbstractFunctional { @@ -33,8 +34,10 @@ class ReadFilterTest extends AbstractFunctional /** * Test load Xlsx file with many empty cells with no filter used. + * + * @param mixed[] $arrayData */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerCellsValues')] + #[DataProvider('providerCellsValues')] public function testXlsxLoadWithoutReadFilter(string $format, array $arrayData): void { $spreadsheet = new Spreadsheet(); @@ -57,8 +60,10 @@ class ReadFilterTest extends AbstractFunctional /** * Test load Xlsx file with many empty cells (and big max row number) with readfilter. + * + * @param mixed[] $arrayData */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerCellsValues')] + #[DataProvider('providerCellsValues')] public function testXlsxLoadWithReadFilter(string $format, array $arrayData): void { $spreadsheet = new Spreadsheet(); diff --git a/tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php b/tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php index 20aecf94b..ea6397f94 100644 --- a/tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php +++ b/tests/PhpSpreadsheetTests/Functional/TypeAttributePreservationTest.php @@ -11,12 +11,14 @@ use PhpOffice\PhpSpreadsheet\Reader\Xlsx as ReaderXlsx; use PhpOffice\PhpSpreadsheet\Reader\Xml as ReaderXml; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as WriterXlsx; +use PHPUnit\Framework\Attributes\DataProvider; class TypeAttributePreservationTest extends AbstractFunctional { public static function providerFormulae(): array { $formats = ['Xlsx']; + /** @var mixed[] */ $data = require 'tests/data/Functional/TypeAttributePreservation/Formula.php'; $result = []; @@ -31,8 +33,10 @@ class TypeAttributePreservationTest extends AbstractFunctional /** * Ensure saved spreadsheets maintain the correct data type. + * + * @param mixed[] $values */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerFormulae')] + #[DataProvider('providerFormulae')] public function testFormulae(string $format, array $values): void { $spreadsheet = new Spreadsheet(); @@ -62,8 +66,10 @@ class TypeAttributePreservationTest extends AbstractFunctional /** * Ensure saved spreadsheets maintain the correct data type. + * + * @param mixed[] $values */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerFormulae')] + #[DataProvider('providerFormulae')] public function testFormulaeNoPrecalc(string $format, array $values): void { $spreadsheet = new Spreadsheet(); diff --git a/tests/PhpSpreadsheetTests/HashTableTest.php b/tests/PhpSpreadsheetTests/HashTableTest.php index 086ee6f05..9eab48696 100644 --- a/tests/PhpSpreadsheetTests/HashTableTest.php +++ b/tests/PhpSpreadsheetTests/HashTableTest.php @@ -10,6 +10,7 @@ use PHPUnit\Framework\TestCase; class HashTableTest extends TestCase { + /** @return array{Comment, Comment} */ public static function createArray(): array { $comment1 = new Comment(); diff --git a/tests/PhpSpreadsheetTests/Shared/CodePageTest.php b/tests/PhpSpreadsheetTests/Shared/CodePageTest.php index 448bff3e9..bce6a19f1 100644 --- a/tests/PhpSpreadsheetTests/Shared/CodePageTest.php +++ b/tests/PhpSpreadsheetTests/Shared/CodePageTest.php @@ -6,6 +6,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Shared\CodePage; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class CodePageTest extends TestCase @@ -13,7 +14,7 @@ class CodePageTest extends TestCase /** * @param string|string[] $expectedResult */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerCodePage')] + #[DataProvider('providerCodePage')] public function testCodePageNumberToName(array|string $expectedResult, int $codePageIndex): void { if ($expectedResult === 'exception') { @@ -41,6 +42,7 @@ class CodePageTest extends TestCase } $tests = $this->providerCodePage(); foreach ($tests as $test) { + /** @var string[] $test */ $covered[$test[1]] = 1; } foreach ($covered as $key => $val) { diff --git a/tests/PhpSpreadsheetTests/Shared/Font2Test.php b/tests/PhpSpreadsheetTests/Shared/Font2Test.php index e35ae3e3b..6dde85b1d 100644 --- a/tests/PhpSpreadsheetTests/Shared/Font2Test.php +++ b/tests/PhpSpreadsheetTests/Shared/Font2Test.php @@ -6,11 +6,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Font; use PhpOffice\PhpSpreadsheet\Style\Font as StyleFont; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class Font2Test extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('providerCharsetFromFontName')] + #[DataProvider('providerCharsetFromFontName')] public function testCharsetFromFontName(string $fontName, int $expectedResult): void { $result = Font::getCharsetFromFontName($fontName); @@ -27,6 +28,7 @@ class Font2Test extends TestCase $defaultCovered = false; $tests = $this->providerCharsetFromFontName(); foreach ($tests as $test) { + /** @var string[] $test */ $thisTest = $test[0]; if (array_key_exists($thisTest, $covered)) { $covered[$thisTest] = 1; diff --git a/tests/PhpSpreadsheetTests/Shared/FontFileNameTest.php b/tests/PhpSpreadsheetTests/Shared/FontFileNameTest.php index 54d49976f..138740171 100644 --- a/tests/PhpSpreadsheetTests/Shared/FontFileNameTest.php +++ b/tests/PhpSpreadsheetTests/Shared/FontFileNameTest.php @@ -19,6 +19,7 @@ class FontFileNameTest extends TestCase private string $holdDirectory; + /** @var array> */ private array $holdExtraFontArray; protected function setUp(): void diff --git a/tests/PhpSpreadsheetTests/Shared/Trend/ExponentialBestFitTest.php b/tests/PhpSpreadsheetTests/Shared/Trend/ExponentialBestFitTest.php index 47326f929..fbaf1127f 100644 --- a/tests/PhpSpreadsheetTests/Shared/Trend/ExponentialBestFitTest.php +++ b/tests/PhpSpreadsheetTests/Shared/Trend/ExponentialBestFitTest.php @@ -10,6 +10,9 @@ use PHPUnit\Framework\TestCase; class ExponentialBestFitTest extends TestCase { /** + * @param array $expectedSlope + * @param array $expectedIntersect + * @param array $expectedGoodnessOfFit * @param array $yValues * @param array $xValues */ diff --git a/tests/PhpSpreadsheetTests/Shared/Trend/LinearBestFitTest.php b/tests/PhpSpreadsheetTests/Shared/Trend/LinearBestFitTest.php index f23b9bfca..15686ef01 100644 --- a/tests/PhpSpreadsheetTests/Shared/Trend/LinearBestFitTest.php +++ b/tests/PhpSpreadsheetTests/Shared/Trend/LinearBestFitTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared\Trend; use PhpOffice\PhpSpreadsheet\Shared\Trend\LinearBestFit; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class LinearBestFitTest extends TestCase @@ -12,10 +13,13 @@ class LinearBestFitTest extends TestCase const LBF_PRECISION = 1.0E-8; /** + * @param array $expectedSlope + * @param array $expectedIntersect + * @param array $expectedGoodnessOfFit * @param array $yValues * @param array $xValues */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerLinearBestFit')] + #[DataProvider('providerLinearBestFit')] public function testLinearBestFit( array $expectedSlope, array $expectedIntersect, diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterAverageTop10Test.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterAverageTop10Test.php index 4246707fb..590531dad 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterAverageTop10Test.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterAverageTop10Test.php @@ -7,6 +7,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class AutoFilterAverageTop10Test extends SetupTeardown { @@ -36,7 +37,8 @@ class AutoFilterAverageTop10Test extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerAverage')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerAverage')] public function testAboveAverage(array $expectedVisible, string $rule): void { $sheet = $this->initSheet(); @@ -66,7 +68,8 @@ class AutoFilterAverageTop10Test extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerTop10')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerTop10')] public function testTop10(array $expectedVisible, string $rule, string $ruleType, int $count): void { $sheet = $this->initSheet(); @@ -116,7 +119,8 @@ class AutoFilterAverageTop10Test extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerTop10Ties')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerTop10Ties')] public function testTop10Ties(array $expectedVisible, string $rule, string $ruleType, int $count): void { $sheet = $this->initSheetTies(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterCustomNumericTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterCustomNumericTest.php index 3539df389..de2dfac3d 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterCustomNumericTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterCustomNumericTest.php @@ -8,6 +8,7 @@ use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class AutoFilterCustomNumericTest extends SetupTeardown { @@ -43,7 +44,8 @@ class AutoFilterCustomNumericTest extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCustomRule')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerCustomRule')] public function testCustomTest(array $expectedVisible, string $rule, int $comparand): void { $sheet = $this->initSheet(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterCustomTextTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterCustomTextTest.php index 42aa6b2e2..6df5cdc8a 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterCustomTextTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterCustomTextTest.php @@ -7,6 +7,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class AutoFilterCustomTextTest extends SetupTeardown { @@ -48,7 +49,8 @@ class AutoFilterCustomTextTest extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCustomText')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerCustomText')] public function testCustomTest(array $expectedVisible, string $pattern): void { $sheet = $this->initSheet(); @@ -189,7 +191,8 @@ class AutoFilterCustomTextTest extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCustomRule')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerCustomRule')] public function testCustomRuleTest(array $expectedVisible, string $rule, string $comparand): void { $sheet = $this->initSheet(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterMonthTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterMonthTest.php index 3cbbd2da1..8134119a2 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterMonthTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterMonthTest.php @@ -8,6 +8,7 @@ use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class AutoFilterMonthTest extends SetupTeardown { @@ -52,7 +53,8 @@ class AutoFilterMonthTest extends SetupTeardown $this->maxRow = 9; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerMonth')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerMonth')] public function testMonths(array $expectedVisible, string $rule): void { // Loop to avoid rare edge case where first calculation diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterQuarterTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterQuarterTest.php index afc2c13ef..e9e64a2ad 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterQuarterTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterQuarterTest.php @@ -8,6 +8,7 @@ use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class AutoFilterQuarterTest extends SetupTeardown { @@ -36,7 +37,8 @@ class AutoFilterQuarterTest extends SetupTeardown $this->maxRow = 9; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerQuarter')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerQuarter')] public function testQuarters(array $expectedVisible, string $rule): void { // Loop to avoid rare edge case where first calculation diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTodayTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTodayTest.php index 686fa6d3c..2087921ad 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTodayTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTodayTest.php @@ -7,6 +7,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter; use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; +use PHPUnit\Framework\Attributes\DataProvider; class AutoFilterTodayTest extends SetupTeardown { @@ -19,7 +20,8 @@ class AutoFilterTodayTest extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerYesterdayTodayTomorrow')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerYesterdayTodayTomorrow')] public function testYesterdayTodayTomorrow(array $expectedVisible, string $rule): void { // Loop to avoid rare edge case where first calculation diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterWeekTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterWeekTest.php index 9e40f20b2..94785f2db 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterWeekTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterWeekTest.php @@ -8,6 +8,7 @@ use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class AutoFilterWeekTest extends SetupTeardown { @@ -37,7 +38,8 @@ class AutoFilterWeekTest extends SetupTeardown $this->maxRow = 9; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerWeek')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerWeek')] public function testWeek(array $expectedVisible, string $rule): void { // Loop to avoid rare edge case where first calculation diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterYearTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterYearTest.php index 3928b6902..c1e7c9ad4 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterYearTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterYearTest.php @@ -7,6 +7,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter; use DateTimeImmutable; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; +use PHPUnit\Framework\Attributes\DataProvider; class AutoFilterYearTest extends SetupTeardown { @@ -22,7 +23,8 @@ class AutoFilterYearTest extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerYear')] + /** @param mixed[] $expectedVisible */ + #[DataProvider('providerYear')] public function testYears(array $expectedVisible, string $rule): void { // Loop to avoid rare edge case where first calculation diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/RuleCustomTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/RuleCustomTest.php index 174eefb88..c5ae77122 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/RuleCustomTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/RuleCustomTest.php @@ -7,6 +7,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class RuleCustomTest extends SetupTeardown { @@ -28,7 +29,8 @@ class RuleCustomTest extends SetupTeardown return $sheet; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCondition')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerCondition')] public function testRuleCondition(array $expectedResult, string $condition): void { $sheet = $this->initSheet(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/SetupTeardown.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/SetupTeardown.php index bdb512c52..24436f6ba 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/SetupTeardown.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/SetupTeardown.php @@ -45,11 +45,13 @@ class SetupTeardown extends TestCase return $this->sheet; } + /** @return int[] */ public function getVisible(): array { return $this->getVisibleSheet($this->getSheet()); } + /** @return int[] */ public function getVisibleSheet(Worksheet $sheet): array { $sheet->getAutoFilter()->showHideRows(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoSizeTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoSizeTest.php index 558590bfb..307594e21 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoSizeTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoSizeTest.php @@ -59,6 +59,7 @@ class AutoSizeTest extends TestCase return $table; } + /** @return float[] */ private function readColumnSizes(): array { $columnSizes = []; diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorEmptyTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorEmptyTest.php index cd4c1f7dc..b075a6ace 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorEmptyTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorEmptyTest.php @@ -9,6 +9,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\CellIterator; use PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ColumnIteratorEmptyTest extends TestCase @@ -32,7 +33,7 @@ class ColumnIteratorEmptyTest extends TestCase return $sheet; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyColumnBasic')] + #[DataProvider('emptyColumnBasicProvider')] public function testIteratorEmptyColumn(string $columnId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -45,7 +46,7 @@ class ColumnIteratorEmptyTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function emptyColumnBasic(): array + public static function emptyColumnBasicProvider(): array { return [ ['A', false], @@ -60,7 +61,7 @@ class ColumnIteratorEmptyTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyColumnNullAsEmpty')] + #[DataProvider('emptyColumnNullAsEmptyProvider')] public function testIteratorEmptyColumnWithNull(string $columnId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -73,7 +74,7 @@ class ColumnIteratorEmptyTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function emptyColumnNullAsEmpty(): array + public static function emptyColumnNullAsEmptyProvider(): array { return [ ['A', false], @@ -88,7 +89,7 @@ class ColumnIteratorEmptyTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyColumnEmptyStringAsEmpty')] + #[DataProvider('emptyColumnEmptyStringAsEmptyProvider')] public function testIteratorEmptyColumnWithEmptyString(string $columnId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -101,7 +102,7 @@ class ColumnIteratorEmptyTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function emptyColumnEmptyStringAsEmpty(): array + public static function emptyColumnEmptyStringAsEmptyProvider(): array { return [ ['A', false], @@ -116,7 +117,7 @@ class ColumnIteratorEmptyTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyColumnNullAndEmptyStringAsEmpty')] + #[DataProvider('emptyColumnNullAndEmptyStringAsEmptyProvider')] public function testIteratorEmptyColumnWithNullAndEmptyString(string $columnId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -131,7 +132,7 @@ class ColumnIteratorEmptyTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function emptyColumnNullAndEmptyStringAsEmpty(): array + public static function emptyColumnNullAndEmptyStringAsEmptyProvider(): array { return [ ['A', false], diff --git a/tests/PhpSpreadsheetTests/Worksheet/MergeBehaviourTest.php b/tests/PhpSpreadsheetTests/Worksheet/MergeBehaviourTest.php index eff6e7e6e..499f68793 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/MergeBehaviourTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/MergeBehaviourTest.php @@ -7,16 +7,17 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; +use PHPUnit\Framework\Attributes\DataProvider; class MergeBehaviourTest extends AbstractFunctional { - private static array $testDataRaw = [ + private const TEST_DATA_RAW = [ [1.1, 2.2, '=ROUND(A1+B1, 1)'], [4.4, 5.5, '=ROUND(A2+B2, 1)'], ['=ROUND(A1+A2, 1)', '=ROUND(B1+B2, 1)', '=ROUND(A3+B3, 1)'], ]; - private array $testDataFormatted = [ + private const TEST_DATE_FORMATTED = [ ['=DATE(1960, 12, 19)', '=DATE(2022, 09, 15)'], ]; @@ -31,7 +32,7 @@ class MergeBehaviourTest extends AbstractFunctional $mergeRange = 'A1:C3'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); - $worksheet->fromArray(self::$testDataRaw, null, 'A1', true); + $worksheet->fromArray(self::TEST_DATA_RAW, null, 'A1', true); $worksheet->mergeCells($mergeRange); $mergeResult = $worksheet->toArray(null, true, false, false); @@ -48,7 +49,7 @@ class MergeBehaviourTest extends AbstractFunctional $mergeRange = 'A1:B1'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); - $worksheet->fromArray($this->testDataFormatted, null, 'A1', true); + $worksheet->fromArray(self::TEST_DATE_FORMATTED, null, 'A1', true); $worksheet->getStyle($mergeRange)->getNumberFormat()->setFormatCode('yyyy-mm-dd'); $worksheet->mergeCells($mergeRange); @@ -68,7 +69,7 @@ class MergeBehaviourTest extends AbstractFunctional $mergeRange = 'A1:C3'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); - $worksheet->fromArray(self::$testDataRaw, null, 'A1', true); + $worksheet->fromArray(self::TEST_DATA_RAW, null, 'A1', true); $worksheet->mergeCells($mergeRange, Worksheet::MERGE_CELL_CONTENT_HIDE); $mergeResult = $worksheet->toArray(null, true, false, false); @@ -85,7 +86,7 @@ class MergeBehaviourTest extends AbstractFunctional $mergeRange = 'A1:B1'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); - $worksheet->fromArray($this->testDataFormatted, null, 'A1', true); + $worksheet->fromArray(self::TEST_DATE_FORMATTED, null, 'A1', true); $worksheet->getStyle($mergeRange)->getNumberFormat()->setFormatCode('yyyy-mm-dd'); $worksheet->mergeCells($mergeRange, Worksheet::MERGE_CELL_CONTENT_HIDE); @@ -94,7 +95,11 @@ class MergeBehaviourTest extends AbstractFunctional $spreadsheet->disconnectWorksheets(); } - #[\PHPUnit\Framework\Attributes\DataProvider('mergeCellsMergeBehaviourProvider')] + /** + * @param mixed[] $testData + * @param mixed[] $expectedResult + */ + #[DataProvider('mergeCellsMergeBehaviourProvider')] public function testMergeCellsMergeBehaviour(array $testData, string $mergeRange, array $expectedResult): void { $spreadsheet = new Spreadsheet(); @@ -113,7 +118,7 @@ class MergeBehaviourTest extends AbstractFunctional { return [ 'With Calculated Values' => [ - self::$testDataRaw, + self::TEST_DATA_RAW, 'A1:C3', [ ['1.1 2.2 1.1 4.4 5.5 0 1.1 0 0', null, null], @@ -155,7 +160,7 @@ class MergeBehaviourTest extends AbstractFunctional $mergeRange = 'A1:B1'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); - $worksheet->fromArray($this->testDataFormatted, null, 'A1', true); + $worksheet->fromArray(self::TEST_DATE_FORMATTED, null, 'A1', true); $worksheet->getStyle($mergeRange)->getNumberFormat()->setFormatCode('yyyy-mm-dd'); $worksheet->mergeCells($mergeRange, Worksheet::MERGE_CELL_CONTENT_MERGE); diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorEmptyTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorEmptyTest.php index 86baa4ac7..33203cdb6 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorEmptyTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorEmptyTest.php @@ -9,6 +9,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\CellIterator; use PhpOffice\PhpSpreadsheet\Worksheet\RowIterator; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class RowIteratorEmptyTest extends TestCase @@ -32,7 +33,7 @@ class RowIteratorEmptyTest extends TestCase return $sheet; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyRowBasic')] + #[DataProvider('emptyRowBasicProvider')] public function testIteratorEmptyRow(int $rowId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -47,7 +48,7 @@ class RowIteratorEmptyTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function emptyRowBasic(): array + public static function emptyRowBasicProvider(): array { return [ [1, false], @@ -62,7 +63,7 @@ class RowIteratorEmptyTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyRowNullAsEmpty')] + #[DataProvider('emptyRowNullAsEmptyProvider')] public function testIteratorEmptyRowWithNull(int $rowId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -75,7 +76,7 @@ class RowIteratorEmptyTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function emptyRowNullAsEmpty(): array + public static function emptyRowNullAsEmptyProvider(): array { return [ [1, false], @@ -90,7 +91,7 @@ class RowIteratorEmptyTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyRowEmptyStringAsEmpty')] + #[DataProvider('emptyRowEmptyStringAsEmptyProvider')] public function testIteratorEmptyRowWithEmptyString(int $rowId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -103,7 +104,7 @@ class RowIteratorEmptyTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function emptyRowEmptyStringAsEmpty(): array + public static function emptyRowEmptyStringAsEmptyProvider(): array { return [ [1, false], @@ -118,7 +119,7 @@ class RowIteratorEmptyTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyRowNullAndEmptyStringAsEmpty')] + #[DataProvider('emptyRowNullAndEmptyStringAsEmptyProvider')] public function testIteratorEmptyRowWithNullAndEmptyString(int $rowId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -133,7 +134,7 @@ class RowIteratorEmptyTest extends TestCase $spreadsheet->disconnectWorksheets(); } - public static function emptyRowNullAndEmptyStringAsEmpty(): array + public static function emptyRowNullAndEmptyStringAsEmptyProvider(): array { return [ [1, false], diff --git a/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php b/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php index 70eb67267..3edbe79b1 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php @@ -166,6 +166,7 @@ class TableTest extends SetupTeardown } } + /** @return array{array{array{int, int, int, int}|CellRange|string, string}} */ public function validTableRanges(): array { $sheet = $this->getSheet(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php b/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php index 251e66c39..c80652de2 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php @@ -13,6 +13,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\CellIterator; use PhpOffice\PhpSpreadsheet\Worksheet\Table; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class WorksheetTest extends TestCase @@ -34,7 +35,7 @@ class WorksheetTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('setTitleInvalidProvider')] + #[DataProvider('setTitleInvalidProvider')] public function testSetTitleInvalid(string $title, string $expectMessage): void { // First, test setting title with validation disabled -- should be successful @@ -89,7 +90,7 @@ class WorksheetTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('setCodeNameInvalidProvider')] + #[DataProvider('setCodeNameInvalidProvider')] public function testSetCodeNameInvalid(string $codeName, string $expectMessage): void { // First, test setting code name with validation disabled -- should be successful @@ -147,7 +148,7 @@ class WorksheetTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('extractSheetTitleProvider')] + #[DataProvider('extractSheetTitleProvider')] public function testExtractSheetTitle(string $range, string $expectTitle, string $expectCell, string $expectCell2): void { // only cell reference @@ -270,7 +271,11 @@ class WorksheetTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('removeColumnProvider')] + /** + * @param mixed[] $initialData + * @param mixed[] $expectedData + */ + #[DataProvider('removeColumnProvider')] public function testRemoveColumn( array $initialData, string $columnToBeRemoved, @@ -419,7 +424,11 @@ class WorksheetTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('removeRowsProvider')] + /** + * @param mixed[] $initialData + * @param mixed[] $expectedData + */ + #[DataProvider('removeRowsProvider')] public function testRemoveRows( array $initialData, int $rowToRemove, @@ -475,7 +484,7 @@ class WorksheetTest extends TestCase return $sheet; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyRowProvider')] + #[DataProvider('emptyRowProvider')] public function testIsEmptyRow(int $rowId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -502,7 +511,7 @@ class WorksheetTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('emptyColumnProvider')] + #[DataProvider('emptyColumnProvider')] public function testIsEmptyColumn(string $columnId, bool $expectedEmpty): void { $spreadsheet = new Spreadsheet(); @@ -552,7 +561,12 @@ class WorksheetTest extends TestCase self::assertInstanceOf(Table::class, $table); } - #[\PHPUnit\Framework\Attributes\DataProvider('toArrayHiddenRowsProvider')] + /** + * @param mixed[] $initialData + * @param int[] $hiddenRows + * @param mixed[] $expectedData + */ + #[DataProvider('toArrayHiddenRowsProvider')] public function testHiddenRows( array $initialData, array $hiddenRows, @@ -563,7 +577,9 @@ class WorksheetTest extends TestCase $worksheet->fromArray($initialData); foreach ($hiddenRows as $hiddenRow) { - $worksheet->getRowDimension($hiddenRow)->setVisible(false); + $worksheet + ->getRowDimension($hiddenRow) + ->setVisible(false); } self::assertSame($expectedData, $worksheet->toArray(null, false, false, true, true)); @@ -585,7 +601,12 @@ class WorksheetTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('toArrayHiddenColumnsProvider')] + /** + * @param mixed[] $initialData + * @param string[] $hiddenColumns + * @param mixed[] $expectedData + */ + #[DataProvider('toArrayHiddenColumnsProvider')] public function testHiddenColumns( array $initialData, array $hiddenColumns, @@ -596,7 +617,9 @@ class WorksheetTest extends TestCase $worksheet->fromArray($initialData); foreach ($hiddenColumns as $hiddenColumn) { - $worksheet->getColumnDimension($hiddenColumn)->setVisible(false); + $worksheet + ->getColumnDimension($hiddenColumn) + ->setVisible(false); } self::assertSame($expectedData, $worksheet->toArray(null, false, false, true, true)); @@ -618,7 +641,8 @@ class WorksheetTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('rangeToArrayProvider')] + /** @param mixed[] $expected */ + #[DataProvider('rangeToArrayProvider')] public function testRangeToArrayWithCellRangeObject(array $expected, string $fromCell, string $toCell): void { $initialData = array_chunk(range('A', 'Y'), 5);