diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5243681117..3979ae510e 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -29,3 +29,13 @@ parameters: message: "#^Binary operation \"/\" between float and array\\|float\\|int\\|string results in an error\\.$#" count: 1 path: src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php + + - + message: "#^Offset 2 does not exist on array\\{int, int, int, int\\}\\|array\\{int, int\\}\\.$#" + count: 1 + path: src/PhpSpreadsheet/Worksheet/Validations.php + + - + message: "#^Offset 3 does not exist on array\\{int, int, int, int\\}\\|array\\{int, int\\}\\.$#" + count: 1 + path: src/PhpSpreadsheet/Worksheet/Validations.php diff --git a/src/PhpSpreadsheet/Cell/CellAddress.php b/src/PhpSpreadsheet/Cell/CellAddress.php index 65ec1cd377..3cd39404f8 100644 --- a/src/PhpSpreadsheet/Cell/CellAddress.php +++ b/src/PhpSpreadsheet/Cell/CellAddress.php @@ -30,6 +30,10 @@ public function __destruct() $this->worksheet = null; } + /** + * @phpstan-assert int|numeric-string $columnId + * @phpstan-assert int|numeric-string $rowId + */ private static function validateColumnAndRow(mixed $columnId, mixed $rowId): void { if (!is_numeric($columnId) || $columnId <= 0 || !is_numeric($rowId) || $rowId <= 0) { diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index f60d3d8f1c..a822c7540a 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -318,11 +318,9 @@ public static function columnIndexFromString(?string $columnAddress): int /** * String from column index. * - * @param int $columnIndex Column index (A = 1) - * - * @return string + * @param int|numeric-string $columnIndex Column index (A = 1) */ - public static function stringFromColumnIndex($columnIndex) + public static function stringFromColumnIndex(int|string $columnIndex): string { static $indexCache = []; static $lookupCache = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ'; diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter.php b/src/PhpSpreadsheet/Worksheet/AutoFilter.php index 215aa00154..ec50e8c83f 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter.php @@ -49,7 +49,7 @@ public function setEvaluated(bool $value): void /** * Create a new AutoFilter. * - * @param AddressRange|array|string $range + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range * A simple string containing a Cell range like 'A1:E10' is permitted * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or an AddressRange object. @@ -105,7 +105,7 @@ public function getRange() /** * Set AutoFilter Cell Range. * - * @param AddressRange|array|string $range + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range * A simple string containing a Cell range like 'A1:E10' or a Cell address like 'A1' is permitted * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or an AddressRange object. diff --git a/src/PhpSpreadsheet/Worksheet/Table.php b/src/PhpSpreadsheet/Worksheet/Table.php index e591797376..8f8b7be987 100644 --- a/src/PhpSpreadsheet/Worksheet/Table.php +++ b/src/PhpSpreadsheet/Worksheet/Table.php @@ -69,7 +69,7 @@ class Table implements Stringable /** * Create a new Table. * - * @param AddressRange|array|string $range + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range * A simple string containing a Cell range like 'A1:E10' is permitted * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or an AddressRange object. @@ -273,7 +273,7 @@ public function getRange(): string /** * Set Table Cell Range. * - * @param AddressRange|array|string $range + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range * A simple string containing a Cell range like 'A1:E10' is permitted * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or an AddressRange object. diff --git a/src/PhpSpreadsheet/Worksheet/Validations.php b/src/PhpSpreadsheet/Worksheet/Validations.php index db4535d3a1..d6e5582809 100644 --- a/src/PhpSpreadsheet/Worksheet/Validations.php +++ b/src/PhpSpreadsheet/Worksheet/Validations.php @@ -36,7 +36,7 @@ public static function validateCellAddress($cellAddress): string /** * Validate a cell address or cell range. * - * @param AddressRange|array|CellAddress|int|string $cellRange Coordinate of the cells as a string, eg: 'C5:F12'; + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $cellRange Coordinate of the cells as a string, eg: 'C5:F12'; * or as an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 12]), * or as a CellAddress or AddressRange object. */ @@ -59,11 +59,11 @@ public static function validateCellOrCellRange($cellRange): string /** * Validate a cell range. * - * @param AddressRange|array|string $cellRange Coordinate of the cells as a string, eg: 'C5:F12'; + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $cellRange Coordinate of the cells as a string, eg: 'C5:F12'; * or as an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 12]), * or as an AddressRange object. */ - public static function validateCellRange($cellRange): string + public static function validateCellRange(AddressRange|array|string $cellRange): string { if (is_string($cellRange)) { [$worksheet, $addressRange] = Worksheet::extractSheetTitle($cellRange, true); diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index ab32e08ef0..437cc77da4 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -1526,7 +1526,7 @@ public function getStyles() /** * Get style for cell. * - * @param AddressRange|array|CellAddress|int|string $cellCoordinate + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $cellCoordinate * A simple string containing a cell address like 'A1' or a cell range like 'A1:E10' * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or a CellAddress or AddressRange object. @@ -1873,7 +1873,7 @@ public function getColumnBreaks() /** * Set merge on a cell range. * - * @param AddressRange|array|string $range A simple string containing a Cell range like 'A1:E10' + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range A simple string containing a Cell range like 'A1:E10' * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or an AddressRange. * @param string $behaviour How the merged cells should behave. @@ -2029,7 +2029,7 @@ public function mergeCellsByColumnAndRow($columnIndex1, $row1, $columnIndex2, $r /** * Remove merge on a cell range. * - * @param AddressRange|array|string $range A simple string containing a Cell range like 'A1:E10' + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $range A simple string containing a Cell range like 'A1:E10' * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or an AddressRange. * @@ -2106,7 +2106,7 @@ public function setMergeCells(array $mergeCells): static /** * Set protection on a cell or cell range. * - * @param AddressRange|array|CellAddress|int|string $range A simple string containing a Cell range like 'A1:E10' + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $range A simple string containing a Cell range like 'A1:E10' * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or a CellAddress or AddressRange object. * @param string $password Password to unlock the protection @@ -2157,7 +2157,7 @@ public function protectCellsByColumnAndRow($columnIndex1, $row1, $columnIndex2, /** * Remove protection on a cell or cell range. * - * @param AddressRange|array|CellAddress|int|string $range A simple string containing a Cell range like 'A1:E10' + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $range A simple string containing a Cell range like 'A1:E10' * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or a CellAddress or AddressRange object. * @@ -2225,7 +2225,7 @@ public function getAutoFilter() /** * Set AutoFilter. * - * @param AddressRange|array|AutoFilter|string $autoFilterOrRange + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|AutoFilter|string $autoFilterOrRange * A simple string containing a Cell range like 'A1:E10' is permitted for backward compatibility * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or an AddressRange. @@ -3041,7 +3041,7 @@ public function setSelectedCell($coordinate): static /** * Select a range of cells. * - * @param AddressRange|array|CellAddress|int|string $coordinate A simple string containing a Cell range like 'A1:E10' + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|CellAddress|int|string $coordinate A simple string containing a Cell range like 'A1:E10' * or passing in an array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow] (e.g. [3, 5, 6, 8]), * or a CellAddress or AddressRange object. * diff --git a/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php b/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php index 33acde1259..0af783135d 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php @@ -156,7 +156,7 @@ public function testGetRange(): void } /** - * @param AddressRange|array|string $fullRange + * @param AddressRange|array{0: int, 1: int, 2: int, 3: int}|array{0: int, 1: int}|string $fullRange */ public function xtestSetRangeValidRange(string|array|AddressRange $fullRange, string $actualRange): void {