Skip to content

Phpstan Level 9 - Part 4 of Many #4410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
330 changes: 0 additions & 330 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,323 +1,5 @@
parameters:
ignoreErrors:
-
message: '#^Parameter \#1 \$str1 of static method PhpOffice\\PhpSpreadsheet\\Calculation\\BinaryComparison\:\:strcmpAllowNull\(\) expects string\|null, mixed given\.$#'
identifier: argument.type
count: 3
path: src/PhpSpreadsheet/Calculation/BinaryComparison.php

-
message: '#^Parameter \#1 \$str1 of static method PhpOffice\\PhpSpreadsheet\\Calculation\\BinaryComparison\:\:strcmpLowercaseFirst\(\) expects string\|null, mixed given\.$#'
identifier: argument.type
count: 2
path: src/PhpSpreadsheet/Calculation/BinaryComparison.php

-
message: '#^Parameter \#2 \$str2 of static method PhpOffice\\PhpSpreadsheet\\Calculation\\BinaryComparison\:\:strcmpAllowNull\(\) expects string\|null, mixed given\.$#'
identifier: argument.type
count: 3
path: src/PhpSpreadsheet/Calculation/BinaryComparison.php

-
message: '#^Parameter \#2 \$str2 of static method PhpOffice\\PhpSpreadsheet\\Calculation\\BinaryComparison\:\:strcmpLowercaseFirst\(\) expects string\|null, mixed given\.$#'
identifier: argument.type
count: 2
path: src/PhpSpreadsheet/Calculation/BinaryComparison.php

-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 4
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\*" between mixed and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\*\*" between mixed and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\*\=" between mixed and \-1\|0\.01 results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\*\=" between mixed and mixed results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\+" between mixed and 1 results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\+" between mixed and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\+\=" between mixed and mixed results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\-" between mixed and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\-\=" between mixed and mixed results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\." between ''Pruned branch \(only…'' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\." between ''a '' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\." between ''a boolean with a…''\|''a floating point…''\|''a matrix with a…''\|''a string with a…''\|''an integer number…'' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\." between ''onlyIf\-'' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 4
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\." between ''onlyIfNot\-'' and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 4
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\." between mixed and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "/" between mixed and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Binary operation "/\=" between mixed and mixed results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset ''onlyIf'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset ''onlyIfNot'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset ''reference'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 3
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset ''storeKey'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset ''type'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 3
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset ''value'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset \(float\|int\) on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset \(int\|string\) on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset 0 on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 4
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset int\<0, max\> on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 41
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset mixed on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot call method push\(\) on mixed\.$#'
identifier: method.nonObject
count: 4
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Calculation\:\:makeError\(\) should return string but returns mixed\.$#'
identifier: return.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$array of function array_intersect_key expects array, mixed given\.$#'
identifier: argument.type
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$branchPruningEnabled of class PhpOffice\\PhpSpreadsheet\\Calculation\\Engine\\BranchPruner constructor expects bool, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$columnAddress of static method PhpOffice\\PhpSpreadsheet\\Cell\\Coordinate\:\:columnIndexFromString\(\) expects string\|null, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$formula of method PhpOffice\\PhpSpreadsheet\\Calculation\\Calculation\:\:_calculateFormulaValue\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$matrix of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Calculation\:\:getMatrixDimensions\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$operand of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Engine\\FormattedNumber\:\:convertToNumberIfFormatted\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$string of function strtoupper expects string, mixed given\.$#'
identifier: argument.type
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$type of method PhpOffice\\PhpSpreadsheet\\Calculation\\Token\\Stack\:\:push\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#1 \$worksheetName of method PhpOffice\\PhpSpreadsheet\\Spreadsheet\:\:getSheetByName\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#2 \$subject of function preg_match expects string, mixed given\.$#'
identifier: argument.type
count: 3
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#2 \.\.\.\$arrays of function array_intersect_key expects array, mixed given\.$#'
identifier: argument.type
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#3 \$reference of method PhpOffice\\PhpSpreadsheet\\Calculation\\Token\\Stack\:\:push\(\) expects string\|null, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#3 \$subject of function preg_replace_callback expects array\<float\|int\|string\>\|string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Parameter &\$stack by\-ref type of method PhpOffice\\PhpSpreadsheet\\Calculation\\Calculation\:\:executeNumericBinaryOperation\(\) expects PhpOffice\\PhpSpreadsheet\\Calculation\\Token\\Stack, mixed given\.$#'
identifier: parameterByRef.type
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Part \$token \(mixed\) of encapsed string cannot be cast to string\.$#'
identifier: encapsedStringPart.nonString
count: 2
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Property PhpOffice\\PhpSpreadsheet\\Calculation\\Calculation\:\:\$branchPruningEnabled \(bool\) does not accept mixed\.$#'
identifier: assign.propertyType
count: 1
path: src/PhpSpreadsheet/Calculation/Calculation.php

-
message: '#^Cannot access offset int\|string\|null on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
Expand Down Expand Up @@ -1086,24 +768,12 @@ parameters:
count: 1
path: src/PhpSpreadsheet/Calculation/TextData/Concatenate.php

-
message: '#^Cannot access offset int\<0, max\> on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 11
path: src/PhpSpreadsheet/Calculation/TextData/Concatenate.php

-
message: '#^Cannot cast mixed to string\.$#'
identifier: cast.string
count: 1
path: src/PhpSpreadsheet/Calculation/TextData/Concatenate.php

-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\TextData\\Concatenate\:\:concatenate2Args\(\) should return array\|string but returns mixed\.$#'
identifier: return.type
count: 2
path: src/PhpSpreadsheet/Calculation/TextData/Concatenate.php

-
message: '#^Parameter \#1 \$ignoreEmpty of static method PhpOffice\\PhpSpreadsheet\\Calculation\\TextData\\Concatenate\:\:evaluateTextJoinArray\(\) expects bool, mixed given\.$#'
identifier: argument.type
Expand Down
23 changes: 14 additions & 9 deletions src/PhpSpreadsheet/Calculation/BinaryComparison.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@ class BinaryComparison
/**
* Compare two strings in the same way as strcmp() except that lowercase come before uppercase letters.
*
* @param null|string $str1 First string value for the comparison
* @param null|string $str2 Second string value for the comparison
* @param mixed $str1 First string value for the comparison, expect ?string
* @param mixed $str2 Second string value for the comparison, expect ?string
*/
private static function strcmpLowercaseFirst(?string $str1, ?string $str2): int
private static function strcmpLowercaseFirst(mixed $str1, mixed $str2): int
{
$inversedStr1 = StringHelper::strCaseReverse($str1 ?? '');
$inversedStr2 = StringHelper::strCaseReverse($str2 ?? '');
$str1 = StringHelper::convertToString($str1);
$str2 = StringHelper::convertToString($str2);
$inversedStr1 = StringHelper::strCaseReverse($str1);
$inversedStr2 = StringHelper::strCaseReverse($str2);

return strcmp($inversedStr1, $inversedStr2);
}

/**
* PHP8.1 deprecates passing null to strcmp.
*
* @param null|string $str1 First string value for the comparison
* @param null|string $str2 Second string value for the comparison
* @param mixed $str1 First string value for the comparison, expect ?string
* @param mixed $str2 Second string value for the comparison, expect ?string
*/
private static function strcmpAllowNull(?string $str1, ?string $str2): int
private static function strcmpAllowNull(mixed $str1, mixed $str2): int
{
return strcmp($str1 ?? '', $str2 ?? '');
$str1 = StringHelper::convertToString($str1);
$str2 = StringHelper::convertToString($str2);

return strcmp($str1, $str2);
}

public static function compare(mixed $operand1, mixed $operand2, string $operator): bool
Expand Down
Loading