Skip to content

Commit 5a9055c

Browse files
committed
Phpstan Level 10 (Final)
Fix all of Statistical. We can now use Level 10 going forward.
1 parent 6b2767c commit 5a9055c

33 files changed

+221
-77
lines changed

phpstan-baseline.neon

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: '#^Parameter \#1 \$array of function array_multisort expects array, mixed given\.$#'
5+
identifier: argument.type
6+
count: 1
7+
path: src/PhpSpreadsheet/Calculation/LookupRef/Sort.php
8+
9+
-
10+
message: '#^Cannot call method getAllSpContainers\(\) on mixed\.$#'
11+
identifier: method.nonObject
12+
count: 1
13+
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
14+
15+
-
16+
message: '#^Cannot call method getBSECollection\(\) on mixed\.$#'
17+
identifier: method.nonObject
18+
count: 1
19+
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
20+
21+
-
22+
message: '#^Cannot call method getBstoreContainer\(\) on mixed\.$#'
23+
identifier: method.nonObject
24+
count: 1
25+
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
26+
27+
-
28+
message: '#^Cannot call method getSpgrContainer\(\) on mixed\.$#'
29+
identifier: method.nonObject
30+
count: 1
31+
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
32+
33+
-
34+
message: '#^Cannot access offset 0 on mixed\.$#'
35+
identifier: offsetAccess.nonOffsetAccessible
36+
count: 1
37+
path: src/PhpSpreadsheet/ReferenceHelper.php
38+
39+
-
40+
message: '#^Parameter \#1 \$string of function trim expects string, mixed given\.$#'
41+
identifier: argument.type
42+
count: 1
43+
path: src/PhpSpreadsheet/ReferenceHelper.php
44+
45+
-
46+
message: '#^Cannot call method setParent\(\) on mixed\.$#'
47+
identifier: method.nonObject
48+
count: 1
49+
path: src/PhpSpreadsheet/Worksheet/AutoFilter.php

phpstan.neon.dist

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ includes:
77
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
88

99
parameters:
10-
level: 9
10+
level: 10
1111
paths:
1212
- samples/
1313
- src/
@@ -21,13 +21,13 @@ parameters:
2121
- src/PhpSpreadsheet/Collection/Memory/SimpleCache3.php
2222
- src/PhpSpreadsheet/Writer/ZipStream2.php
2323
- src/PhpSpreadsheet/Writer/ZipStream3.php
24-
#- tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php
24+
- tests/PhpSpreadsheetTests/Writer/Xlsx/ArrayFunctions2Test.php
2525
parallel:
2626
processTimeout: 300.0
2727
ignoreErrors:
2828
# Accept a bit anything for assert methods
2929
- '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~'
30-
#- '~Method .*rovider.* return type has no value type specified in iterable type array\.$~'
31-
#- '~Method .*rovider.* should return array but returns mixed\.$~'
32-
#- '~.* has parameter \$expectedResult with no value type specified in iterable type array\.$~'
33-
- identifier: missingType.iterableValue
30+
- '~Method .*rovider.* return type has no value type specified in iterable type array\.$~'
31+
- '~Method .*rovider.* should return array but returns mixed\.$~'
32+
- '~.* has parameter \$expectedResult with no value type specified in iterable type array\.$~'
33+
#- identifier: missingType.iterableValue

src/PhpSpreadsheet/Calculation/Statistical/Averages.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public static function median(mixed ...$args): float|string
156156

157157
$returnValue = ExcelError::NAN();
158158

159+
/** @var array<float|int> */
159160
$aArgs = self::filterArguments($aArgs);
160161
$valueCount = count($aArgs);
161162
if ($valueCount > 0) {
@@ -199,6 +200,11 @@ public static function mode(mixed ...$args): float|string
199200
return $returnValue;
200201
}
201202

203+
/**
204+
* @param mixed[] $args
205+
*
206+
* @return mixed[]
207+
*/
202208
protected static function filterArguments(array $args): array
203209
{
204210
return array_filter(
@@ -213,6 +219,8 @@ function ($value): bool {
213219
/**
214220
* Special variant of array_count_values that isn't limited to strings and integers,
215221
* but can work with floating point numbers as values.
222+
*
223+
* @param mixed[] $data
216224
*/
217225
private static function modeCalc(array $data): float|string
218226
{
@@ -222,9 +230,11 @@ private static function modeCalc(array $data): float|string
222230
$maxfreqkey = '';
223231
$maxfreqdatum = '';
224232
foreach ($data as $datum) {
233+
/** @var float|string $datum */
225234
$found = false;
226235
++$index;
227236
foreach ($frequencyArray as $key => $value) {
237+
/** @var string[] $value */
228238
if ((string) $value['value'] == (string) $datum) {
229239
++$frequencyArray[$key]['frequency'];
230240
$freq = $frequencyArray[$key]['frequency'];

src/PhpSpreadsheet/Calculation/Statistical/Conditional.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Conditional
2626
* AVERAGEIF(range,condition[, average_range])
2727
*
2828
* @param mixed $range Data values, expect array
29-
* @param null|array|string $condition the criteria that defines which cells will be checked
29+
* @param null|mixed[]|string $condition the criteria that defines which cells will be checked
3030
* @param mixed $averageRange Data values
3131
*/
3232
public static function AVERAGEIF(mixed $range, null|array|string $condition, mixed $averageRange = []): null|int|float|string
@@ -84,7 +84,7 @@ public static function AVERAGEIFS(mixed ...$args): null|int|float|string
8484
* COUNTIF(range,condition)
8585
*
8686
* @param mixed $range Data values, expect array
87-
* @param null|array|string $condition the criteria that defines which cells will be counted
87+
* @param null|mixed[]|string $condition the criteria that defines which cells will be counted
8888
*/
8989
public static function COUNTIF(mixed $range, null|array|string $condition): string|int
9090
{
@@ -234,15 +234,23 @@ public static function SUMIFS(mixed ...$args): null|float|string
234234
return DSum::evaluate($database, self::VALUE_COLUMN_NAME, $conditions);
235235
}
236236

237-
/** @param array $args */
237+
/**
238+
* @param mixed[] $args
239+
*
240+
* @return mixed[][]
241+
*/
238242
private static function buildConditionSet(...$args): array
239243
{
240244
$conditions = self::buildConditions(1, ...$args);
241245

242246
return array_map(null, ...$conditions);
243247
}
244248

245-
/** @param array $args */
249+
/**
250+
* @param mixed[] $args
251+
*
252+
* @return mixed[][]
253+
*/
246254
private static function buildConditionSetForValueRange(...$args): array
247255
{
248256
$conditions = self::buildConditions(2, ...$args);
@@ -257,7 +265,11 @@ private static function buildConditionSetForValueRange(...$args): array
257265
return array_map(null, ...$conditions);
258266
}
259267

260-
/** @param array $args */
268+
/**
269+
* @param mixed[] $args
270+
*
271+
* @return mixed[][]
272+
*/
261273
private static function buildConditions(int $startOffset, ...$args): array
262274
{
263275
$conditions = [];
@@ -272,15 +284,23 @@ private static function buildConditions(int $startOffset, ...$args): array
272284
return $conditions;
273285
}
274286

275-
/** @param array $args */
287+
/**
288+
* @param mixed[] $args
289+
*
290+
* @return mixed[]
291+
*/
276292
private static function buildDatabase(...$args): array
277293
{
278294
$database = [];
279295

280296
return self::buildDataSet(0, $database, ...$args);
281297
}
282298

283-
/** @param array $args */
299+
/**
300+
* @param mixed[] $args
301+
*
302+
* @return mixed[]
303+
*/
284304
private static function buildDatabaseWithValueRange(...$args): array
285305
{
286306
$database = [];
@@ -292,7 +312,12 @@ private static function buildDatabaseWithValueRange(...$args): array
292312
return self::buildDataSet(1, $database, ...$args);
293313
}
294314

295-
/** @param array $args */
315+
/**
316+
* @param mixed[][] $database
317+
* @param mixed[] $args
318+
*
319+
* @return mixed[]
320+
*/
296321
private static function buildDataSet(int $startOffset, array $database, ...$args): array
297322
{
298323
$pairCount = 1;
@@ -308,6 +333,12 @@ private static function buildDataSet(int $startOffset, array $database, ...$args
308333
return array_map(null, ...$database);
309334
}
310335

336+
/**
337+
* @param mixed[] $range
338+
* @param mixed[] $valueRange
339+
*
340+
* @return mixed[]
341+
*/
311342
private static function databaseFromRangeAndValue(array $range, array $valueRange = []): array
312343
{
313344
$range = Functions::flattenArray($range);

src/PhpSpreadsheet/Calculation/Statistical/Confidence.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Confidence
2323
* @param mixed $size As an integer
2424
* Or can be an array of values
2525
*
26-
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
26+
* @return array<mixed>|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
2727
* with the same dimensions
2828
*/
2929
public static function CONFIDENCE(mixed $alpha, mixed $stdDev, mixed $size)

src/PhpSpreadsheet/Calculation/Statistical/Deviations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function sumSquares(mixed ...$args): string|float
5555
* kurtosis indicates a relatively peaked distribution. Negative kurtosis indicates a
5656
* relatively flat distribution.
5757
*
58-
* @param array ...$args Data Series
58+
* @param mixed[] ...$args Data Series
5959
*/
6060
public static function kurtosis(...$args): string|int|float
6161
{
@@ -98,7 +98,7 @@ public static function kurtosis(...$args): string|int|float
9898
* asymmetric tail extending toward more positive values. Negative skewness indicates a
9999
* distribution with an asymmetric tail extending toward more negative values.
100100
*
101-
* @param array ...$args Data Series
101+
* @param mixed[] ...$args Data Series
102102
*
103103
* @return float|int|string The result, or a string containing an error
104104
*/

src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Beta
3333
* @param mixed $rMax as an float
3434
* Or can be an array of values
3535
*
36-
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
36+
* @return array<mixed>|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
3737
* with the same dimensions
3838
*/
3939
public static function distribution(mixed $value, mixed $alpha, mixed $beta, mixed $rMin = 0.0, mixed $rMax = 1.0): array|string|float
@@ -86,7 +86,7 @@ public static function distribution(mixed $value, mixed $alpha, mixed $beta, mix
8686
* @param mixed $rMax Maximum value as a float
8787
* Or can be an array of values
8888
*
89-
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
89+
* @return array<mixed>|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
9090
* with the same dimensions
9191
*/
9292
public static function inverse(mixed $probability, mixed $alpha, mixed $beta, mixed $rMin = 0.0, mixed $rMax = 1.0): array|string|float

src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Binomial
3030
* @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false)
3131
* Or can be an array of values
3232
*
33-
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
33+
* @return array<mixed>|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
3434
* with the same dimensions
3535
*/
3636
public static function distribution(mixed $value, mixed $trials, mixed $probability, mixed $cumulative)
@@ -78,7 +78,7 @@ public static function distribution(mixed $value, mixed $trials, mixed $probabil
7878
* If null, then this will indicate the same as the number of Successes
7979
* Or can be an array of values
8080
*
81-
* @return array|float|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
81+
* @return array<mixed>|float|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
8282
* with the same dimensions
8383
*/
8484
public static function range(mixed $trials, mixed $probability, mixed $successes, mixed $limit = null): array|string|float|int
@@ -132,7 +132,7 @@ public static function range(mixed $trials, mixed $probability, mixed $successes
132132
* @param mixed $probability Probability of success on each trial as a float
133133
* Or can be an array of values
134134
*
135-
* @return array|float|string The result, or a string containing an error
135+
* @return array<mixed>|float|string The result, or a string containing an error
136136
* If an array of numbers is passed as an argument, then the returned result will also be an array
137137
* with the same dimensions
138138
*
@@ -181,7 +181,7 @@ public static function negative(mixed $failures, mixed $successes, mixed $probab
181181
* @param mixed $alpha criterion value as a float
182182
* Or can be an array of values
183183
*
184-
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
184+
* @return array<mixed>|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
185185
* with the same dimensions
186186
*/
187187
public static function inverse(mixed $trials, mixed $probability, mixed $alpha): array|string|int

src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ChiSquared
2323
* @param mixed $degrees Integer degrees of freedom
2424
* Or can be an array of values
2525
*
26-
* @return array|float|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
26+
* @return array<mixed>|float|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
2727
* with the same dimensions
2828
*/
2929
public static function distributionRightTail(mixed $value, mixed $degrees): array|string|int|float
@@ -65,7 +65,7 @@ public static function distributionRightTail(mixed $value, mixed $degrees): arra
6565
* @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false)
6666
* Or can be an array of values
6767
*
68-
* @return array|float|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
68+
* @return array<mixed>|float|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
6969
* with the same dimensions
7070
*/
7171
public static function distributionLeftTail(mixed $value, mixed $degrees, mixed $cumulative): array|string|int|float
@@ -113,7 +113,7 @@ public static function distributionLeftTail(mixed $value, mixed $degrees, mixed
113113
* @param mixed $degrees Integer degrees of freedom
114114
* Or can be an array of values
115115
*
116-
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
116+
* @return array<mixed>|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
117117
* with the same dimensions
118118
*/
119119
public static function inverseRightTail(mixed $probability, mixed $degrees)
@@ -133,7 +133,7 @@ public static function inverseRightTail(mixed $probability, mixed $degrees)
133133
return ExcelError::NAN();
134134
}
135135

136-
$callback = fn ($value): float => 1 - (Gamma::incompleteGamma($degrees / 2, $value / 2)
136+
$callback = fn (float $value): float => 1 - (Gamma::incompleteGamma($degrees / 2, $value / 2)
137137
/ Gamma::gammaValue($degrees / 2));
138138

139139
$newtonRaphson = new NewtonRaphson($callback);
@@ -151,7 +151,7 @@ public static function inverseRightTail(mixed $probability, mixed $degrees)
151151
* @param mixed $degrees Integer degrees of freedom
152152
* Or can be an array of values
153153
*
154-
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
154+
* @return array<mixed>|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
155155
* with the same dimensions
156156
*/
157157
public static function inverseLeftTail(mixed $probability, mixed $degrees): array|string|float
@@ -181,13 +181,15 @@ public static function inverseLeftTail(mixed $probability, mixed $degrees): arra
181181
* (of observed and expected frequencies), are likely to be simply due to sampling error,
182182
* or if they are likely to be real.
183183
*
184-
* @param array $actual an array of observed frequencies
185-
* @param array $expected an array of expected frequencies
184+
* @param float[] $actual an array of observed frequencies
185+
* @param float[] $expected an array of expected frequencies
186186
*/
187187
public static function test($actual, $expected): float|string
188188
{
189189
$rows = count($actual);
190+
/** @var float[] */
190191
$actual = Functions::flattenArray($actual);
192+
/** @var float[] */
191193
$expected = Functions::flattenArray($expected);
192194
$columns = intdiv(count($actual), $rows);
193195

src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Exponential
2424
* @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false)
2525
* Or can be an array of values
2626
*
27-
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
27+
* @return array<mixed>|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
2828
* with the same dimensions
2929
*/
3030
public static function distribution(mixed $value, mixed $lambda, mixed $cumulative): array|string|float

0 commit comments

Comments
 (0)