Clean Up Some Other Phpstan Annotations

Mostly remove `phpstan-ignore-line` in a number of places. Very minor code changes to Worksheet/AutoFilter and Reader/Xlsx.
This commit is contained in:
oleibman
2026-06-25 13:54:00 -07:00
parent a5e7ea2fb0
commit 7f331bca4c
13 changed files with 16 additions and 26 deletions
+1
View File
@@ -8,6 +8,7 @@ includes:
parameters:
level: 10
treatPhpDocTypesAsCertain: false
paths:
- samples/
- src/
@@ -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)) {
@@ -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;
@@ -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;
}
@@ -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),
+1 -1
View File
@@ -745,7 +745,7 @@ abstract class Coordinate
}
}
if ($rowStart !== null) { // @phpstan-ignore-line
if ($rowStart !== null) {
if ($rowStart == $rowEnd) {
$ranges[] = $hashedValue->col . $rowStart;
} else {
+2 -4
View File
@@ -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);
}
+1 -1
View File
@@ -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;
}
+1 -2
View File
@@ -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);
}
@@ -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;
@@ -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;
+2 -5
View File
@@ -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);
+1 -2
View File
@@ -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');
}
}