diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bbe5e3641..29ec2fc13 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,6 +8,7 @@ includes: parameters: level: 10 + treatPhpDocTypesAsCertain: false paths: - samples/ - src/ diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index f379ff1fc..09c8c20d1 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -640,7 +640,7 @@ class Calculation extends CalculationLocale if ($this->formulaTokenCacheMaxSize > 0) { // Phpstan says if condition is always false, // but coverage report says next statement is covered. - if (count($this->formulaTokenCache) >= $this->formulaTokenCacheMaxSize) { // @phpstan-ignore-line + if (count($this->formulaTokenCache) >= $this->formulaTokenCacheMaxSize) { $this->formulaTokenCache = []; } // Cache key is the original formula string (before ANCHORARRAY transformation) @@ -1391,7 +1391,7 @@ class Calculation extends CalculationLocale // do we now have a function/variable/number? $expectingOperator = true; $expectingOperand = false; - $val = $match[1] ?? ''; //* @phpstan-ignore-line + $val = $match[1] ?? ''; $length = strlen($val); if (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $val, $matches)) { diff --git a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php index 53668d134..130e4c103 100644 --- a/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php +++ b/src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php @@ -166,7 +166,7 @@ class NonPeriodic $foundneg = false; for ($i = 0; $i < $valCount; ++$i) { $fld = $values[$i]; - if (!is_numeric($fld)) { //* @phpstan-ignore-line + if (!is_numeric($fld)) { return ExcelError::VALUE(); } elseif ($fld > 0) { $foundpos = true; diff --git a/src/PhpSpreadsheet/Calculation/Information/Value.php b/src/PhpSpreadsheet/Calculation/Information/Value.php index 4fee352c6..8280bc5ef 100644 --- a/src/PhpSpreadsheet/Calculation/Information/Value.php +++ b/src/PhpSpreadsheet/Calculation/Information/Value.php @@ -54,9 +54,7 @@ class Value } try { - // Phpstan claims cellValue can't be null. - // I don't see why. - [$column, $row] = Coordinate::indexesFromString($cellValue ?? ''); // @phpstan-ignore-line + [$column, $row] = Coordinate::indexesFromString($cellValue ?? ''); } catch (SpreadsheetException) { return false; } diff --git a/src/PhpSpreadsheet/Calculation/LookupRef/Filter.php b/src/PhpSpreadsheet/Calculation/LookupRef/Filter.php index 486194e46..3106d4e7e 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef/Filter.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef/Filter.php @@ -58,7 +58,7 @@ class Filter */ private static function filterByRow(array $lookupArray, array $matchArray): array { - $matchArray = array_values(array_column($matchArray, 0)); // @phpstan-ignore-line + $matchArray = array_values(array_column($matchArray, 0)); return array_filter( array_values($lookupArray), diff --git a/src/PhpSpreadsheet/Cell/Coordinate.php b/src/PhpSpreadsheet/Cell/Coordinate.php index f7daa9d9b..038c4b065 100644 --- a/src/PhpSpreadsheet/Cell/Coordinate.php +++ b/src/PhpSpreadsheet/Cell/Coordinate.php @@ -745,7 +745,7 @@ abstract class Coordinate } } - if ($rowStart !== null) { // @phpstan-ignore-line + if ($rowStart !== null) { if ($rowStart == $rowEnd) { $ranges[] = $hashedValue->col . $rowStart; } else { diff --git a/src/PhpSpreadsheet/IOFactory.php b/src/PhpSpreadsheet/IOFactory.php index 7444aa879..7e4010f66 100644 --- a/src/PhpSpreadsheet/IOFactory.php +++ b/src/PhpSpreadsheet/IOFactory.php @@ -265,8 +265,7 @@ abstract class IOFactory */ public static function registerWriter(string $writerType, string $writerClass): void { - // We want phpstan to validate caller, but still need this test - if (!is_a($writerClass, IWriter::class, true)) { //* @phpstan-ignore-line + if (!is_a($writerClass, IWriter::class, true)) { throw new Writer\Exception('Registered writers must implement ' . IWriter::class); } @@ -280,8 +279,7 @@ abstract class IOFactory */ public static function registerReader(string $readerType, string $readerClass): void { - // We want phpstan to validate caller, but still need this test - if (!is_a($readerClass, IReader::class, true)) { //* @phpstan-ignore-line + if (!is_a($readerClass, IReader::class, true)) { throw new Reader\Exception('Registered readers must implement ' . IReader::class); } diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index b05ae877e..0c0199676 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -2403,7 +2403,7 @@ class Xlsx extends BaseReader { $returnValue = null; $protectKey = $protection[$key]; - if (!empty($protectKey)) { + if (isset($protectKey)) { $protectKey = (string) $protectKey; $returnValue = $protectKey !== 'false' && (bool) $protectKey; } diff --git a/src/PhpSpreadsheet/Settings.php b/src/PhpSpreadsheet/Settings.php index 9c2beaa03..7759d9250 100644 --- a/src/PhpSpreadsheet/Settings.php +++ b/src/PhpSpreadsheet/Settings.php @@ -52,8 +52,7 @@ class Settings */ public static function setChartRenderer(string $rendererClassName): void { - // We want phpstan to validate caller, but still need this test - if (!is_a($rendererClassName, IRenderer::class, true)) { //* @phpstan-ignore-line + if (!is_a($rendererClassName, IRenderer::class, true)) { throw new Exception('Chart renderer must implement ' . IRenderer::class); } diff --git a/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php b/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php index 435e6a60d..6d23b9d92 100644 --- a/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php +++ b/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/CellValue.php @@ -192,8 +192,7 @@ class CellValue extends WizardAbstract implements WizardInterface $retVal = true; $array = array_merge(array_keys(self::SINGLE_OPERATORS), array_keys(self::RANGE_OPERATORS)); foreach ($array as $value) { - // PhpStan is correct about next statement, but we want to test anyhow - $retVal = $retVal && in_array($value, self::MAGIC_OPERATIONS, true); // @phpstan-ignore-line + $retVal = $retVal && in_array($value, self::MAGIC_OPERATIONS, true); } return $retVal; diff --git a/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/TextValue.php b/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/TextValue.php index 934a364ab..c1657666d 100644 --- a/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/TextValue.php +++ b/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/TextValue.php @@ -169,8 +169,7 @@ class TextValue extends WizardAbstract implements WizardInterface $retVal = true; $array = array_keys(self::OPERATORS); foreach ($array as $value) { - // PhpStan is correct about next statement, but we want to test anyhow - $retVal = $retVal && in_array($value, self::MAGIC_OPERATIONS, true); // @phpstan-ignore-line + $retVal = $retVal && in_array($value, self::MAGIC_OPERATIONS, true); } return $retVal; diff --git a/src/PhpSpreadsheet/Worksheet/AutoFilter.php b/src/PhpSpreadsheet/Worksheet/AutoFilter.php index 04070e5d9..05afcfb24 100644 --- a/src/PhpSpreadsheet/Worksheet/AutoFilter.php +++ b/src/PhpSpreadsheet/Worksheet/AutoFilter.php @@ -752,14 +752,11 @@ class AutoFilter implements Stringable private function dynamicFilterDateRange(string $dynamicRuleType, AutoFilter\Column &$filterColumn): array { $ruleValues = []; - $callBack = [__CLASS__, self::DATE_FUNCTIONS[$dynamicRuleType]]; // What if not found? + $callBack = [__CLASS__, self::DATE_FUNCTIONS[$dynamicRuleType] ?? throw new Exception("invalid dynamic rule type $dynamicRuleType")]; // Calculate start/end dates for the required date range based on current date // Val is lowest permitted value. // Maxval is greater than highest permitted value - $val = $maxval = 0; - if (is_callable($callBack)) { //* @phpstan-ignore-line - [$val, $maxval] = $callBack(); - } + [$val, $maxval] = $callBack(); $val = Date::dateTimeToExcel($val); $maxval = Date::dateTimeToExcel($maxval); diff --git a/src/PhpSpreadsheet/Worksheet/Worksheet.php b/src/PhpSpreadsheet/Worksheet/Worksheet.php index f6a2c4ba1..d3e9e4dd3 100644 --- a/src/PhpSpreadsheet/Worksheet/Worksheet.php +++ b/src/PhpSpreadsheet/Worksheet/Worksheet.php @@ -1687,8 +1687,7 @@ class Worksheet public function duplicateConditionalStyle(array $styles, string $range = ''): static { foreach ($styles as $cellStyle) { - // Php runtime doesn't support docblock declaration - if (!($cellStyle instanceof Conditional)) { // @phpstan-ignore-line + if (!($cellStyle instanceof Conditional)) { throw new Exception('Style is not a conditional style'); } }