diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ee013549..7d9bd63a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -66,7 +66,7 @@ parameters: path: src/PhpSpreadsheet/Calculation/Calculation.php - - message: "#^Cannot access offset int on mixed\\.$#" + message: "#^Cannot access offset int(<0, max>)? on mixed\\.$#" count: 16 path: src/PhpSpreadsheet/Calculation/Calculation.php @@ -1461,7 +1461,7 @@ parameters: path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php - - message: "#^Parameter \\#1 \\$array_arg of function uasort expects array, mixed given\\.$#" + message: "#^Parameter \\#1 \\$array_arg of function uasort expects array()?, mixed given\\.$#" count: 1 path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php @@ -1471,7 +1471,7 @@ parameters: path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php - - message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(mixed, mixed\\)\\: int, array\\{'self', 'vlookupSort'\\} given\\.$#" + message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\((mixed|T), (mixed|T)\\)\\: int, array\\{'self', 'vlookupSort'\\} given\\.$#" count: 1 path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php @@ -5205,11 +5205,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Shared/StringHelper.php - - - message: "#^Static property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:\\$isIconvEnabled \\(bool\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/StringHelper.php - - message: "#^Static property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:\\$thousandsSeparator \\(string\\) in isset\\(\\) is not nullable\\.$#" count: 1 @@ -5365,11 +5360,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php - - - message: "#^Array \\(array\\\\) does not accept object\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/Trend/Trend.php - - message: "#^Call to an undefined method object\\:\\:getGoodnessOfFit\\(\\)\\.$#" count: 1 @@ -5705,16 +5695,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php - - - message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(\\)\\: mixed, array\\{'self', 'escapeQuotesCallback'\\} given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php - - - - message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(\\)\\: mixed, array\\{'self', 'setLowercaseCallback'\\} given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php - - message: "#^Parameter \\#2 \\$replace of function str_replace expects array\\|string, int given\\.$#" count: 1 @@ -5730,11 +5710,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php - - - message: "#^Parameter \\#3 \\$subject of function preg_replace_callback expects array\\|string, string\\|null given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\NumberFormat\\\\Formatter\\:\\:splitFormat\\(\\) has no return type specified\\.$#" count: 1 @@ -5890,11 +5865,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php - - - message: "#^Array \\(array\\\\) does not accept mixed\\.$#" - count: 1 - path: src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php - - message: "#^Cannot call method setParent\\(\\) on mixed\\.$#" count: 1 @@ -6076,7 +6046,7 @@ parameters: path: src/PhpSpreadsheet/Worksheet/Worksheet.php - - message: "#^Parameter \\#1 \\$row of method PhpOffice\\\\PhpSpreadsheet\\\\Collection\\\\Cells\\:\\:removeRow\\(\\) expects string, int given\\.$#" + message: "#^Parameter \\#1 \\$row of method PhpOffice\\\\PhpSpreadsheet\\\\Collection\\\\Cells\\:\\:removeRow\\(\\) expects string, int(<1, max>)? given\\.$#" count: 2 path: src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -7026,7 +6996,7 @@ parameters: path: src/PhpSpreadsheet/Writer/Xlsx.php - - message: "#^Cannot access offset int on mixed\\.$#" + message: "#^Cannot access offset int(<0, max>)? on mixed\\.$#" count: 2 path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php @@ -7191,7 +7161,7 @@ parameters: path: src/PhpSpreadsheet/Writer/Xlsx/DocProps.php - - message: "#^Parameter \\#1 \\$index of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getChartByIndex\\(\\) expects string, int given\\.$#" + message: "#^Parameter \\#1 \\$index of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:getChartByIndex\\(\\) expects string, int(<0, max>)? given\\.$#" count: 1 path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php @@ -7431,7 +7401,7 @@ parameters: path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php - - message: "#^Offset int on array\\\\> in isset\\(\\) does not exist\\.$#" + message: "#^Offset int(<1, max>)? on array\\\\> in isset\\(\\) does not exist\\.$#" count: 2 path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php @@ -7466,18 +7436,8 @@ parameters: path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php - - message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int given\\.$#" - count: 19 - path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php - - - - message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int\\<0, max\\> given\\.$#" - count: 3 - path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php - - - - message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int\\<1, max\\> given\\.$#" - count: 7 + message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, (int|int\\<(0|1), max\\>) given\\.$#" + count: 27 path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php - diff --git a/phpstan-conditional.php b/phpstan-conditional.php index 5501039b..c5d28dd6 100644 --- a/phpstan-conditional.php +++ b/phpstan-conditional.php @@ -42,7 +42,7 @@ if (PHP_VERSION_ID < 80000) { ]; // Erroneous analysis by Phpstan before PHP8 - mb_strlen does not return false $config['parameters']['ignoreErrors'][] = [ - 'message' => '#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:countCharacters\\(\\) should return int but returns int\\|false\\.$#', + 'message' => '#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:countCharacters\\(\\) should return int but returns int(<0, max>)?\\|false\\.$#', 'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/StringHelper.php', 'count' => 1, ]; diff --git a/src/PhpSpreadsheet/Calculation/Financial/Coupons.php b/src/PhpSpreadsheet/Calculation/Financial/Coupons.php index 3fd6c1d2..e97a7ea8 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/Coupons.php +++ b/src/PhpSpreadsheet/Calculation/Financial/Coupons.php @@ -134,7 +134,7 @@ class Coupons case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL: // Actual/actual if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) { - $daysPerYear = Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis); + $daysPerYear = (int) Helpers::daysPerYear(DateTimeExcel\DateParts::year($settlement), $basis); return $daysPerYear / $frequency; } diff --git a/src/PhpSpreadsheet/Calculation/Statistical/Averages.php b/src/PhpSpreadsheet/Calculation/Statistical/Averages.php index 1a627e99..c6d84e74 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical/Averages.php +++ b/src/PhpSpreadsheet/Calculation/Statistical/Averages.php @@ -24,7 +24,7 @@ class Averages extends AggregateBase $aArgs = Functions::flattenArrayIndexed($args); // Return value - $returnValue = 0; + $returnValue = 0.0; $aMean = self::average(...$args); if ($aMean === Functions::DIV0()) { diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php index 5f96dcfc..1644e40e 100644 --- a/src/PhpSpreadsheet/Reader/Xls.php +++ b/src/PhpSpreadsheet/Reader/Xls.php @@ -7912,4 +7912,17 @@ class Xls extends BaseReader return $value; } + + /** + * Phpstan 1.4.4 complains that this property is never read. + * So, we might be able to get rid of it altogether. + * For now, however, this function makes it readable, + * which satisfies Phpstan. + * + * @codeCoverageIgnore + */ + public function getMapCellStyleXfIndex(): array + { + return $this->mapCellStyleXfIndex; + } } diff --git a/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php b/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php index 5c6ccfd3..66111b6c 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php +++ b/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php @@ -415,7 +415,7 @@ class EigenvalueDecomposition $norm = 0.0; for ($i = 0; $i < $nn; ++$i) { - if (($i < $low) || ($i > $high)) { + if ($i > $high) { $this->d[$i] = $this->H[$i][$i]; $this->e[$i] = 0.0; } @@ -762,7 +762,7 @@ class EigenvalueDecomposition // Vectors of isolated roots for ($i = 0; $i < $nn; ++$i) { - if ($i < $low | $i > $high) { + if ($i > $high) { for ($j = $i; $j < $nn; ++$j) { $this->V[$i][$j] = $this->H[$i][$j]; } diff --git a/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php b/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php index 7a31d77f..fa92fd5d 100644 --- a/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php +++ b/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php @@ -71,12 +71,12 @@ class Root extends PPS $this->fileHandle = $fileHandle; // Initial Setting for saving - $this->bigBlockSize = 2 ** ( + $this->bigBlockSize = (int) (2 ** ( (isset($this->bigBlockSize)) ? self::adjust2($this->bigBlockSize) : 9 - ); - $this->smallBlockSize = 2 ** ( + )); + $this->smallBlockSize = (int) (2 ** ( (isset($this->smallBlockSize)) ? self::adjust2($this->smallBlockSize) : 6 - ); + )); // Make an array of PPS's (for Save) $aList = []; diff --git a/src/PhpSpreadsheet/Shared/StringHelper.php b/src/PhpSpreadsheet/Shared/StringHelper.php index 435d0e4c..9970a211 100644 --- a/src/PhpSpreadsheet/Shared/StringHelper.php +++ b/src/PhpSpreadsheet/Shared/StringHelper.php @@ -49,7 +49,7 @@ class StringHelper /** * Is iconv extension avalable? * - * @var bool + * @var ?bool */ private static $isIconvEnabled; diff --git a/src/PhpSpreadsheet/Shared/Trend/Trend.php b/src/PhpSpreadsheet/Shared/Trend/Trend.php index 61d1183a..1162284b 100644 --- a/src/PhpSpreadsheet/Shared/Trend/Trend.php +++ b/src/PhpSpreadsheet/Shared/Trend/Trend.php @@ -72,6 +72,7 @@ class Trend case self::TREND_POWER: if (!isset(self::$trendCache[$key])) { $className = '\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType . 'BestFit'; + // @phpstan-ignore-next-line self::$trendCache[$key] = new $className($yValues, $xValues, $const); } diff --git a/src/PhpSpreadsheet/Spreadsheet.php b/src/PhpSpreadsheet/Spreadsheet.php index 350ba652..eea28908 100644 --- a/src/PhpSpreadsheet/Spreadsheet.php +++ b/src/PhpSpreadsheet/Spreadsheet.php @@ -313,7 +313,7 @@ class Spreadsheet break; case 'target': case 'data': - if (is_array($this->ribbonXMLData) && isset($this->ribbonXMLData[$what])) { + if (is_array($this->ribbonXMLData)) { $returnData = $this->ribbonXMLData[$what]; } diff --git a/src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php b/src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php index db18e636..5a47a86d 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php @@ -76,11 +76,13 @@ class DateFormatter // general syntax: [$-] // language info is in hexadecimal // strip off chinese part like [DBNum1][$-804] - $format = preg_replace('/^(\[DBNum\d\])*(\[\$[^\]]*\])/i', '', $format); + $format = preg_replace('/^(\[DBNum\d\])*(\[\$[^\]]*\])/i', '', $format) ?? ''; // OpenOffice.org uses upper-case number formats, e.g. 'YYYY', convert to lower-case; // but we don't want to change any quoted strings - $format = preg_replace_callback('/(?:^|")([^"]*)(?:$|")/', ['self', 'setLowercaseCallback'], $format); + /** @var callable */ + $callable = ['self', 'setLowercaseCallback']; + $format = preg_replace_callback('/(?:^|")([^"]*)(?:$|")/', $callable, $format); // Only process the non-quoted blocks for date format characters $blocks = explode('"', $format); @@ -106,7 +108,9 @@ class DateFormatter $format = implode('"', $blocks); // escape any quoted characters so that DateTime format() will render them correctly - $format = preg_replace_callback('/"(.*)"/U', ['self', 'escapeQuotesCallback'], $format); + /** @var callable */ + $callback = ['self', 'escapeQuotesCallback']; + $format = preg_replace_callback('/"(.*)"/U', $callback, $format); $dateObj = Date::excelToDateTimeObject($value); // If the colon preceding minute had been quoted, as happens in diff --git a/src/PhpSpreadsheet/Style/Style.php b/src/PhpSpreadsheet/Style/Style.php index fdb15451..78e5ebbf 100644 --- a/src/PhpSpreadsheet/Style/Style.php +++ b/src/PhpSpreadsheet/Style/Style.php @@ -78,9 +78,7 @@ class Style extends Supervisor * @see Style::applyFromArray() * @see Style::getHashCode() * - * @phpstan-var null|array{styleByHash: array, hashByObjId: array} - * - * @var array + * @var ?array */ private static $cachedStyles; diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php b/src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php index 2e3ea65b..a5d46ec8 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php @@ -394,6 +394,7 @@ class Column foreach ($value as $k => $v) { $cloned = clone $v; $cloned->setParent($this); // attach the new cloned Rule to this new cloned Autofilter Cloned object + // @phpstan-ignore-next-line $this->ruleset[$k] = $cloned; } } else { diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php index a4d28f8a..86f966e7 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php @@ -205,10 +205,10 @@ class Worksheet extends WriterPart // Zoom scales if ($worksheet->getSheetView()->getZoomScale() != 100) { - $objWriter->writeAttribute('zoomScale', $worksheet->getSheetView()->getZoomScale()); + $objWriter->writeAttribute('zoomScale', (string) $worksheet->getSheetView()->getZoomScale()); } if ($worksheet->getSheetView()->getZoomScaleNormal() != 100) { - $objWriter->writeAttribute('zoomScaleNormal', $worksheet->getSheetView()->getZoomScaleNormal()); + $objWriter->writeAttribute('zoomScaleNormal', (string) $worksheet->getSheetView()->getZoomScaleNormal()); } // Show zeros (Excel also writes this attribute only if set to false)