Skip to content

Commit 5dee5a7

Browse files
authored
Merge pull request #4420 from oleibman/stan2lv905
Phpstan Level 9 - Part 5 of Many
2 parents 8aee491 + bc315a3 commit 5dee5a7

File tree

22 files changed

+145
-413
lines changed

22 files changed

+145
-413
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2525
- Start migration to Phpstan level 9. [PR #4396](https://github.com/PHPOffice/PhpSpreadsheet/pull/4396)
2626
- Calculation locale logic moved to separate class. [PR #4398](https://github.com/PHPOffice/PhpSpreadsheet/pull/4398)
2727
- TREND_POLYNOMIAL_* and TREND_BEST_FIT do not work, and are changed to throw Exceptions if attempted. (TREND_BEST_FIT_NO_POLY works.) An attempt to use an unknown trend type will now also throw an exception. [Issue #4400](https://github.com/PHPOffice/PhpSpreadsheet/issues/4400) [PR #4339](https://github.com/PHPOffice/PhpSpreadsheet/pull/4339)
28+
- Month parameter of DATE function will now return VALUE if an ordinal string (e.g. '3rd') is used, but will accept bool or null. [PR #4420](https://github.com/PHPOffice/PhpSpreadsheet/pull/4420)
2829

2930
### Moved
3031

phpstan-baseline.neon

-336
Original file line numberDiff line numberDiff line change
@@ -1,299 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: '#^Cannot access offset int\|string\|null on mixed\.$#'
5-
identifier: offsetAccess.nonOffsetAccessible
6-
count: 1
7-
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
8-
9-
-
10-
message: '#^Parameter \#1 \$array of function array_keys expects array, mixed given\.$#'
11-
identifier: argument.type
12-
count: 1
13-
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
14-
15-
-
16-
message: '#^Parameter \#1 \$callback of function array_map expects \(callable\(mixed\)\: mixed\)\|null, ''strtoupper'' given\.$#'
17-
identifier: argument.type
18-
count: 1
19-
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
20-
21-
-
22-
message: '#^Parameter \#1 \$criteriaNames of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Database\\DatabaseAbstract\:\:buildQuery\(\) expects array, mixed given\.$#'
23-
identifier: argument.type
24-
count: 1
25-
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
26-
27-
-
28-
message: '#^Parameter \#1 \$string of function strtoupper expects string, mixed given\.$#'
29-
identifier: argument.type
30-
count: 1
31-
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
32-
33-
-
34-
message: '#^Parameter \#2 \$array of function array_map expects array, mixed given\.$#'
35-
identifier: argument.type
36-
count: 1
37-
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
38-
39-
-
40-
message: '#^Parameter \#3 \$criteria of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Database\\DatabaseAbstract\:\:executeQuery\(\) expects array, mixed given\.$#'
41-
identifier: argument.type
42-
count: 1
43-
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
44-
45-
-
46-
message: '#^Parameter \#4 \$fields of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Database\\DatabaseAbstract\:\:executeQuery\(\) expects array, mixed given\.$#'
47-
identifier: argument.type
48-
count: 1
49-
path: src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php
50-
51-
-
52-
message: '#^Cannot cast mixed to string\.$#'
53-
identifier: cast.string
54-
count: 1
55-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
56-
57-
-
58-
message: '#^Parameter \#1 \$day of static method PhpOffice\\PhpSpreadsheet\\Shared\\Date\:\:dayStringToNumber\(\) expects string, mixed given\.$#'
59-
identifier: argument.type
60-
count: 1
61-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
62-
63-
-
64-
message: '#^Parameter \#1 \$monthName of static method PhpOffice\\PhpSpreadsheet\\Shared\\Date\:\:monthStringToNumber\(\) expects string, mixed given\.$#'
65-
identifier: argument.type
66-
count: 1
67-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Date.php
68-
69-
-
70-
message: '#^Cannot cast mixed to int\.$#'
71-
identifier: cast.int
72-
count: 3
73-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/DateValue.php
74-
75-
-
76-
message: '#^Parameter \#1 \$dateValue of static method PhpOffice\\PhpSpreadsheet\\Calculation\\DateTimeExcel\\DateValue\:\:fromString\(\) expects array\|bool\|float\|int\|string\|null, mixed given\.$#'
77-
identifier: argument.type
78-
count: 1
79-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
80-
81-
-
82-
message: '#^Parameter \#1 \$excelTimestamp of static method PhpOffice\\PhpSpreadsheet\\Shared\\Date\:\:excelToDateTimeObject\(\) expects float\|int, mixed given\.$#'
83-
identifier: argument.type
84-
count: 1
85-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php
86-
87-
-
88-
message: '#^Parameter \#1 \$timeValue of static method PhpOffice\\PhpSpreadsheet\\Calculation\\DateTimeExcel\\Helpers\:\:getTimeValue\(\) expects string, mixed given\.$#'
89-
identifier: argument.type
90-
count: 3
91-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/TimeParts.php
92-
93-
-
94-
message: '#^Binary operation "/" between mixed and 360 results in an error\.$#'
95-
identifier: binaryOp.invalid
96-
count: 3
97-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
98-
99-
-
100-
message: '#^Binary operation "/" between mixed and 365 results in an error\.$#'
101-
identifier: binaryOp.invalid
102-
count: 1
103-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
104-
105-
-
106-
message: '#^Binary operation "/" between mixed and float\|int results in an error\.$#'
107-
identifier: binaryOp.invalid
108-
count: 1
109-
path: src/PhpSpreadsheet/Calculation/DateTimeExcel/YearFrac.php
110-
111-
-
112-
message: '#^Parameter &\$operand by\-ref type of method PhpOffice\\PhpSpreadsheet\\Calculation\\Engine\\FormattedNumber\:\:convertToNumberIfFraction\(\) expects string, mixed given\.$#'
113-
identifier: parameterByRef.type
114-
count: 1
115-
path: src/PhpSpreadsheet/Calculation/Engine/FormattedNumber.php
116-
117-
-
118-
message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#'
119-
identifier: argument.type
120-
count: 1
121-
path: src/PhpSpreadsheet/Calculation/Engine/Logger.php
122-
123-
-
124-
message: '#^Cannot cast mixed to string\.$#'
125-
identifier: cast.string
126-
count: 1
127-
path: src/PhpSpreadsheet/Calculation/Engineering/ConvertBase.php
128-
129-
-
130-
message: '#^Parameter \#1 \$year of static method PhpOffice\\PhpSpreadsheet\\Calculation\\DateTimeExcel\\Helpers\:\:isLeapYear\(\) expects int\|string, mixed given\.$#'
131-
identifier: argument.type
132-
count: 1
133-
path: src/PhpSpreadsheet/Calculation/Financial/Amortization.php
134-
135-
-
136-
message: '#^Binary operation "\+" between 1 and mixed results in an error\.$#'
137-
identifier: binaryOp.invalid
138-
count: 1
139-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
140-
141-
-
142-
message: '#^Binary operation "\-" between \-1 and mixed results in an error\.$#'
143-
identifier: binaryOp.invalid
144-
count: 1
145-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
146-
147-
-
148-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\CashFlow\\Variable\\NonPeriodic\:\:xnpvOrdered\(\) should return float\|string but returns mixed\.$#'
149-
identifier: return.type
150-
count: 1
151-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
152-
153-
-
154-
message: '#^Parameter \#1 \$values of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\CashFlow\\Variable\\NonPeriodic\:\:xirrBisection\(\) expects array, mixed given\.$#'
155-
identifier: argument.type
156-
count: 1
157-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
158-
159-
-
160-
message: '#^Parameter \#1 \$values of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\CashFlow\\Variable\\NonPeriodic\:\:xirrPart3\(\) expects array, mixed given\.$#'
161-
identifier: argument.type
162-
count: 1
163-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
164-
165-
-
166-
message: '#^Parameter \#2 \$dates of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\CashFlow\\Variable\\NonPeriodic\:\:xirrBisection\(\) expects array, mixed given\.$#'
167-
identifier: argument.type
168-
count: 1
169-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
170-
171-
-
172-
message: '#^Parameter \#2 \$dates of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\CashFlow\\Variable\\NonPeriodic\:\:xirrPart3\(\) expects array, mixed given\.$#'
173-
identifier: argument.type
174-
count: 1
175-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
176-
177-
-
178-
message: '#^Parameter \#2 \$values of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\CashFlow\\Variable\\NonPeriodic\:\:xnpvOrdered\(\) expects array\<int, float\|int\|numeric\-string\>, mixed given\.$#'
179-
identifier: argument.type
180-
count: 7
181-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/NonPeriodic.php
182-
183-
-
184-
message: '#^Binary operation "\+" between 1 and mixed results in an error\.$#'
185-
identifier: binaryOp.invalid
186-
count: 1
187-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php
188-
189-
-
190-
message: '#^Binary operation "\+" between 1\.0 and mixed results in an error\.$#'
191-
identifier: binaryOp.invalid
192-
count: 2
193-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php
194-
195-
-
196-
message: '#^Binary operation "\+" between mixed and float results in an error\.$#'
197-
identifier: binaryOp.invalid
198-
count: 1
199-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php
200-
201-
-
202-
message: '#^Binary operation "\+\=" between mixed and float results in an error\.$#'
203-
identifier: assignOp.invalid
204-
count: 1
205-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php
206-
207-
-
208-
message: '#^Binary operation "\-" between float and mixed results in an error\.$#'
209-
identifier: binaryOp.invalid
210-
count: 2
211-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php
212-
213-
-
214-
message: '#^Binary operation "\-" between mixed and float results in an error\.$#'
215-
identifier: binaryOp.invalid
216-
count: 2
217-
path: src/PhpSpreadsheet/Calculation/Financial/CashFlow/Variable/Periodic.php
218-
219-
-
220-
message: '#^Parameter \#1 \$year of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Helpers\:\:daysPerYear\(\) expects int\|string, mixed given\.$#'
221-
identifier: argument.type
222-
count: 3
223-
path: src/PhpSpreadsheet/Calculation/Financial/Coupons.php
224-
225-
-
226-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\AccruedInterest\:\:atMaturity\(\) should return float\|string but returns mixed\.$#'
227-
identifier: return.type
228-
count: 1
229-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
230-
231-
-
232-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\AccruedInterest\:\:periodic\(\) should return float\|string but returns mixed\.$#'
233-
identifier: return.type
234-
count: 2
235-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/AccruedInterest.php
236-
237-
-
238-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\Price\:\:priceAtMaturity\(\) should return float\|string but returns mixed\.$#'
239-
identifier: return.type
240-
count: 3
241-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
242-
243-
-
244-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\Price\:\:priceDiscounted\(\) should return float\|string but returns mixed\.$#'
245-
identifier: return.type
246-
count: 1
247-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
248-
249-
-
250-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\Price\:\:received\(\) should return float\|string but returns mixed\.$#'
251-
identifier: return.type
252-
count: 1
253-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
254-
255-
-
256-
message: '#^Parameter \#1 \$year of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Helpers\:\:daysPerYear\(\) expects int\|string, mixed given\.$#'
257-
identifier: argument.type
258-
count: 1
259-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Price.php
260-
261-
-
262-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\Rates\:\:discount\(\) should return float\|string but returns mixed\.$#'
263-
identifier: return.type
264-
count: 1
265-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
266-
267-
-
268-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\Rates\:\:interest\(\) should return float\|string but returns mixed\.$#'
269-
identifier: return.type
270-
count: 1
271-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Rates.php
272-
273-
-
274-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\Yields\:\:yieldAtMaturity\(\) should return float\|string but returns mixed\.$#'
275-
identifier: return.type
276-
count: 3
277-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
278-
279-
-
280-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Securities\\Yields\:\:yieldDiscounted\(\) should return float\|string but returns mixed\.$#'
281-
identifier: return.type
282-
count: 1
283-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
284-
285-
-
286-
message: '#^Parameter \#1 \$year of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Helpers\:\:daysPerYear\(\) expects int\|string, mixed given\.$#'
287-
identifier: argument.type
288-
count: 2
289-
path: src/PhpSpreadsheet/Calculation/Financial/Securities/Yields.php
290-
291-
-
292-
message: '#^Parameter \#1 \$year of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Financial\\Helpers\:\:daysPerYear\(\) expects int\|string, mixed given\.$#'
293-
identifier: argument.type
294-
count: 3
295-
path: src/PhpSpreadsheet/Calculation/Financial/TreasuryBill.php
296-
2973
-
2984
message: '#^Binary operation "\." between ''\='' and mixed results in an error\.$#'
2995
identifier: binaryOp.invalid
@@ -354,48 +60,6 @@ parameters:
35460
count: 1
35561
path: src/PhpSpreadsheet/Calculation/Functions.php
35662

357-
-
358-
message: '#^Cannot cast mixed to string\.$#'
359-
identifier: cast.string
360-
count: 1
361-
path: src/PhpSpreadsheet/Calculation/Information/Value.php
362-
363-
-
364-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Information\\Value\:\:asNumber\(\) should return float\|int\|string but returns mixed\.$#'
365-
identifier: return.type
366-
count: 1
367-
path: src/PhpSpreadsheet/Calculation/Information/Value.php
368-
369-
-
370-
message: '#^Parameter \#1 \$coordinate of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Functions\:\:trimSheetFromCellReference\(\) expects string, mixed given\.$#'
371-
identifier: argument.type
372-
count: 1
373-
path: src/PhpSpreadsheet/Calculation/Information/Value.php
374-
375-
-
376-
message: '#^Parameter \#1 \$coordinate of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Functions\:\:trimTrailingRange\(\) expects string, mixed given\.$#'
377-
identifier: argument.type
378-
count: 1
379-
path: src/PhpSpreadsheet/Calculation/Information/Value.php
380-
381-
-
382-
message: '#^Parameter \#1 \$haystack of function str_contains expects string, mixed given\.$#'
383-
identifier: argument.type
384-
count: 1
385-
path: src/PhpSpreadsheet/Calculation/Information/Value.php
386-
387-
-
388-
message: '#^Parameter \#1 \$namedRange of method PhpOffice\\PhpSpreadsheet\\Spreadsheet\:\:getNamedRange\(\) expects string, mixed given\.$#'
389-
identifier: argument.type
390-
count: 1
391-
path: src/PhpSpreadsheet/Calculation/Information/Value.php
392-
393-
-
394-
message: '#^Parameter \#1 \$num1 of function fmod expects float, mixed given\.$#'
395-
identifier: argument.type
396-
count: 2
397-
path: src/PhpSpreadsheet/Calculation/Information/Value.php
398-
39963
-
40064
message: '#^Parameter \#1 \$row of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Address\:\:formatAsA1\(\) expects int, mixed given\.$#'
40165
identifier: argument.type

src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ abstract public static function evaluate(array $database, array|null|int|string
2727
*/
2828
protected static function fieldExtract(array $database, mixed $field): ?int
2929
{
30-
$field = strtoupper(Functions::flattenSingleValue($field) ?? '');
30+
/** @var ?string */
31+
$single = Functions::flattenSingleValue($field);
32+
$field = strtoupper($single ?? '');
3133
if ($field === '') {
3234
return null;
3335
}
3436

35-
$fieldNames = array_map('strtoupper', array_shift($database));
37+
/** @var callable */
38+
$callable = 'strtoupper';
39+
/** @var non-empty-array $database */
40+
$fieldNames = array_map($callable, array_shift($database));
3641
if (is_numeric($field)) {
3742
$field = (int) $field - 1;
3843
if ($field < 0 || $field >= count($fieldNames)) {
@@ -66,7 +71,9 @@ protected static function fieldExtract(array $database, mixed $field): ?int
6671
*/
6772
protected static function filter(array $database, array $criteria): array
6873
{
74+
/** @var array */
6975
$fieldNames = array_shift($database);
76+
/** @var array */
7077
$criteriaNames = array_shift($criteria);
7178

7279
// Convert the criteria into a set of AND/OR conditions with [:placeholders]
@@ -84,6 +91,7 @@ protected static function getFilteredColumn(array $database, ?int $field, array
8491

8592
// extract an array of values for the requested column
8693
$columnData = [];
94+
/** @var array $row */
8795
foreach ($database as $rowKey => $row) {
8896
$keys = array_keys($row);
8997
$key = $keys[$field] ?? null;

0 commit comments

Comments
 (0)