Changes Required For Phpstan 1.4.5 (#2549)

Dependabot pushed Phpstan 1.4.4 and then 1.4.5 (PR #2548). Because of some incompatible error messages between the current and new release, changes are required in order to be compatible with current and new releases.
This commit is contained in:
oleibman 2022-02-05 12:58:56 -08:00 committed by GitHub
parent 454c01be51
commit 59ae5e20b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 45 additions and 68 deletions

View File

@ -66,7 +66,7 @@ parameters:
path: src/PhpSpreadsheet/Calculation/Calculation.php path: src/PhpSpreadsheet/Calculation/Calculation.php
- -
message: "#^Cannot access offset int on mixed\\.$#" message: "#^Cannot access offset int(<0, max>)? on mixed\\.$#"
count: 16 count: 16
path: src/PhpSpreadsheet/Calculation/Calculation.php path: src/PhpSpreadsheet/Calculation/Calculation.php
@ -1461,7 +1461,7 @@ parameters:
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php 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(<T>)?, mixed given\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
@ -1471,7 +1471,7 @@ parameters:
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php 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 count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
@ -5205,11 +5205,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Shared/StringHelper.php 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\\.$#" message: "#^Static property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:\\$thousandsSeparator \\(string\\) in isset\\(\\) is not nullable\\.$#"
count: 1 count: 1
@ -5365,11 +5360,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php path: src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php
-
message: "#^Array \\(array\\<PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\>\\) does not accept object\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Trend/Trend.php
- -
message: "#^Call to an undefined method object\\:\\:getGoodnessOfFit\\(\\)\\.$#" message: "#^Call to an undefined method object\\:\\:getGoodnessOfFit\\(\\)\\.$#"
count: 1 count: 1
@ -5705,16 +5695,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php 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\\.$#" message: "#^Parameter \\#2 \\$replace of function str_replace expects array\\|string, int given\\.$#"
count: 1 count: 1
@ -5730,11 +5710,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php 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\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\NumberFormat\\\\Formatter\\:\\:splitFormat\\(\\) has no return type specified\\.$#"
count: 1 count: 1
@ -5890,11 +5865,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php path: src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php
-
message: "#^Array \\(array\\<PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter\\\\Column\\\\Rule\\>\\) does not accept mixed\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/AutoFilter/Column.php
- -
message: "#^Cannot call method setParent\\(\\) on mixed\\.$#" message: "#^Cannot call method setParent\\(\\) on mixed\\.$#"
count: 1 count: 1
@ -6076,7 +6046,7 @@ parameters:
path: src/PhpSpreadsheet/Worksheet/Worksheet.php 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 count: 2
path: src/PhpSpreadsheet/Worksheet/Worksheet.php path: src/PhpSpreadsheet/Worksheet/Worksheet.php
@ -7026,7 +6996,7 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xlsx.php path: src/PhpSpreadsheet/Writer/Xlsx.php
- -
message: "#^Cannot access offset int on mixed\\.$#" message: "#^Cannot access offset int(<0, max>)? on mixed\\.$#"
count: 2 count: 2
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
@ -7191,7 +7161,7 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xlsx/DocProps.php 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 count: 1
path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php path: src/PhpSpreadsheet/Writer/Xlsx/Drawing.php
@ -7431,7 +7401,7 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
- -
message: "#^Offset int on array\\<string, non\\-empty\\-array\\<int, string\\>\\> in isset\\(\\) does not exist\\.$#" message: "#^Offset int(<1, max>)? on array\\<string, non\\-empty\\-array\\<int, string\\>\\> in isset\\(\\) does not exist\\.$#"
count: 2 count: 2
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
@ -7466,18 +7436,8 @@ parameters:
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
- -
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int given\\.$#" message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, (int|int\\<(0|1), max\\>) given\\.$#"
count: 19 count: 27
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
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
- -

View File

@ -42,7 +42,7 @@ if (PHP_VERSION_ID < 80000) {
]; ];
// Erroneous analysis by Phpstan before PHP8 - mb_strlen does not return false // Erroneous analysis by Phpstan before PHP8 - mb_strlen does not return false
$config['parameters']['ignoreErrors'][] = [ $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', 'path' => __DIR__ . '/src/PhpSpreadsheet/Shared/StringHelper.php',
'count' => 1, 'count' => 1,
]; ];

View File

@ -134,7 +134,7 @@ class Coupons
case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL: case FinancialConstants::BASIS_DAYS_PER_YEAR_ACTUAL:
// Actual/actual // Actual/actual
if ($frequency == FinancialConstants::FREQUENCY_ANNUAL) { 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; return $daysPerYear / $frequency;
} }

View File

@ -24,7 +24,7 @@ class Averages extends AggregateBase
$aArgs = Functions::flattenArrayIndexed($args); $aArgs = Functions::flattenArrayIndexed($args);
// Return value // Return value
$returnValue = 0; $returnValue = 0.0;
$aMean = self::average(...$args); $aMean = self::average(...$args);
if ($aMean === Functions::DIV0()) { if ($aMean === Functions::DIV0()) {

View File

@ -7912,4 +7912,17 @@ class Xls extends BaseReader
return $value; 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;
}
} }

View File

@ -415,7 +415,7 @@ class EigenvalueDecomposition
$norm = 0.0; $norm = 0.0;
for ($i = 0; $i < $nn; ++$i) { for ($i = 0; $i < $nn; ++$i) {
if (($i < $low) || ($i > $high)) { if ($i > $high) {
$this->d[$i] = $this->H[$i][$i]; $this->d[$i] = $this->H[$i][$i];
$this->e[$i] = 0.0; $this->e[$i] = 0.0;
} }
@ -762,7 +762,7 @@ class EigenvalueDecomposition
// Vectors of isolated roots // Vectors of isolated roots
for ($i = 0; $i < $nn; ++$i) { for ($i = 0; $i < $nn; ++$i) {
if ($i < $low | $i > $high) { if ($i > $high) {
for ($j = $i; $j < $nn; ++$j) { for ($j = $i; $j < $nn; ++$j) {
$this->V[$i][$j] = $this->H[$i][$j]; $this->V[$i][$j] = $this->H[$i][$j];
} }

View File

@ -71,12 +71,12 @@ class Root extends PPS
$this->fileHandle = $fileHandle; $this->fileHandle = $fileHandle;
// Initial Setting for saving // Initial Setting for saving
$this->bigBlockSize = 2 ** ( $this->bigBlockSize = (int) (2 ** (
(isset($this->bigBlockSize)) ? self::adjust2($this->bigBlockSize) : 9 (isset($this->bigBlockSize)) ? self::adjust2($this->bigBlockSize) : 9
); ));
$this->smallBlockSize = 2 ** ( $this->smallBlockSize = (int) (2 ** (
(isset($this->smallBlockSize)) ? self::adjust2($this->smallBlockSize) : 6 (isset($this->smallBlockSize)) ? self::adjust2($this->smallBlockSize) : 6
); ));
// Make an array of PPS's (for Save) // Make an array of PPS's (for Save)
$aList = []; $aList = [];

View File

@ -49,7 +49,7 @@ class StringHelper
/** /**
* Is iconv extension avalable? * Is iconv extension avalable?
* *
* @var bool * @var ?bool
*/ */
private static $isIconvEnabled; private static $isIconvEnabled;

View File

@ -72,6 +72,7 @@ class Trend
case self::TREND_POWER: case self::TREND_POWER:
if (!isset(self::$trendCache[$key])) { if (!isset(self::$trendCache[$key])) {
$className = '\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType . 'BestFit'; $className = '\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType . 'BestFit';
// @phpstan-ignore-next-line
self::$trendCache[$key] = new $className($yValues, $xValues, $const); self::$trendCache[$key] = new $className($yValues, $xValues, $const);
} }

View File

@ -313,7 +313,7 @@ class Spreadsheet
break; break;
case 'target': case 'target':
case 'data': case 'data':
if (is_array($this->ribbonXMLData) && isset($this->ribbonXMLData[$what])) { if (is_array($this->ribbonXMLData)) {
$returnData = $this->ribbonXMLData[$what]; $returnData = $this->ribbonXMLData[$what];
} }

View File

@ -76,11 +76,13 @@ class DateFormatter
// general syntax: [$<Currency string>-<language info>] // general syntax: [$<Currency string>-<language info>]
// language info is in hexadecimal // language info is in hexadecimal
// strip off chinese part like [DBNum1][$-804] // 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; // OpenOffice.org uses upper-case number formats, e.g. 'YYYY', convert to lower-case;
// but we don't want to change any quoted strings // 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 // Only process the non-quoted blocks for date format characters
$blocks = explode('"', $format); $blocks = explode('"', $format);
@ -106,7 +108,9 @@ class DateFormatter
$format = implode('"', $blocks); $format = implode('"', $blocks);
// escape any quoted characters so that DateTime format() will render them correctly // 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); $dateObj = Date::excelToDateTimeObject($value);
// If the colon preceding minute had been quoted, as happens in // If the colon preceding minute had been quoted, as happens in

View File

@ -78,9 +78,7 @@ class Style extends Supervisor
* @see Style::applyFromArray() * @see Style::applyFromArray()
* @see Style::getHashCode() * @see Style::getHashCode()
* *
* @phpstan-var null|array{styleByHash: array<string, Style>, hashByObjId: array<int, string>} * @var ?array<string, array>
*
* @var array<string, array>
*/ */
private static $cachedStyles; private static $cachedStyles;

View File

@ -394,6 +394,7 @@ class Column
foreach ($value as $k => $v) { foreach ($value as $k => $v) {
$cloned = clone $v; $cloned = clone $v;
$cloned->setParent($this); // attach the new cloned Rule to this new cloned Autofilter Cloned object $cloned->setParent($this); // attach the new cloned Rule to this new cloned Autofilter Cloned object
// @phpstan-ignore-next-line
$this->ruleset[$k] = $cloned; $this->ruleset[$k] = $cloned;
} }
} else { } else {

View File

@ -205,10 +205,10 @@ class Worksheet extends WriterPart
// Zoom scales // Zoom scales
if ($worksheet->getSheetView()->getZoomScale() != 100) { if ($worksheet->getSheetView()->getZoomScale() != 100) {
$objWriter->writeAttribute('zoomScale', $worksheet->getSheetView()->getZoomScale()); $objWriter->writeAttribute('zoomScale', (string) $worksheet->getSheetView()->getZoomScale());
} }
if ($worksheet->getSheetView()->getZoomScaleNormal() != 100) { 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) // Show zeros (Excel also writes this attribute only if set to false)