Skip to content

Commit 43af27a

Browse files
committed
fixed PHPStan errors
1 parent 4c9d11e commit 43af27a

File tree

4 files changed

+102
-9
lines changed

4 files changed

+102
-9
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"require-dev": {
2121
"nette/tester": "^2.5",
2222
"tracy/tracy": "^2.9",
23-
"phpstan/phpstan-nette": "^2.0@stable",
23+
"phpstan/phpstan": "^2.0@stable",
2424
"jetbrains/phpstorm-attributes": "^1.2"
2525
},
2626
"conflict": {

phpstan.neon

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 5
2+
level: 6
33

44
paths:
55
- src
@@ -8,12 +8,102 @@ parameters:
88
bootstrapFiles:
99
- tests/phpstan-bootstrap.php
1010

11+
excludePaths:
12+
- src/compatibility.php
13+
- src/Iterators/Mapper.php
14+
- src/Utils/ObjectHelpers.php
15+
1116
ignoreErrors:
12-
# PHPStan does not support dynamic by reference return used by Nette\Utils\Strings::pcre()
13-
- '#Undefined variable: \$m#'
17+
# Intentional design pattern: new static() for inheritance support in fluent interfaces
18+
-
19+
identifier: new.static
20+
paths:
21+
- src/Utils/ArrayHash.php
22+
- src/Utils/ArrayList.php
23+
- src/Utils/DateTime.php
24+
- src/Utils/Finder.php
25+
- src/Utils/Html.php
26+
- src/Utils/Image.php
27+
28+
# Runtime validation: ArrayAccess methods receive mixed types, validation is necessary
29+
-
30+
identifier: function.alreadyNarrowedType
31+
paths:
32+
- src/Utils/ArrayHash.php
33+
- src/Utils/ArrayList.php
34+
35+
# Runtime validation: isList check validates input at runtime
36+
-
37+
identifier: staticMethod.alreadyNarrowedType
38+
path: src/Utils/ArrayList.php
39+
40+
# Runtime validation: is_callable check validates callback at runtime
41+
-
42+
identifier: function.alreadyNarrowedType
43+
path: src/Utils/Strings.php
44+
45+
# Intentional pattern: using && for short-circuit evaluation with side effects
46+
-
47+
identifier: booleanAnd.leftAlwaysTrue
48+
path: src/Utils/DateTime.php
49+
reportUnmatched: false
50+
51+
# Intentional pattern: assignment in condition with && operator
52+
-
53+
identifier: booleanAnd.rightAlwaysTrue
54+
path: src/Utils/Reflection.php
55+
56+
# PHP 8.3+: getBytesFromString() doesn't exist on PHP 8.2
57+
-
58+
identifier: method.notFound
59+
path: src/Utils/Random.php
60+
reportUnmatched: false
61+
62+
# Intentional pattern: ??= for caching filter results, variable is declared via reference
63+
-
64+
identifier: nullCoalesce.variable
65+
path: src/Utils/Finder.php
66+
67+
# Type test files: assertType() is the side effect, comparison warnings are expected
68+
-
69+
identifier: greater.alwaysTrue
70+
path: tests/types/utils-types.php
71+
72+
# Image.php: Callback signature intentionally simplified (doesn't use int parameter)
73+
-
74+
identifier: argument.type
75+
path: src/Utils/Image.php
76+
count: 1
77+
78+
# Image.php: Defensive validation even though phpDoc specifies positive-int
79+
-
80+
identifiers:
81+
- smaller.alwaysFalse
82+
- booleanOr.alwaysFalse
83+
path: src/Utils/Image.php
84+
85+
# Image.php: isset() check for type safety even though offset always exists
86+
-
87+
identifier: isset.offset
88+
path: src/Utils/Image.php
89+
90+
# Image.php: Match arms document all supported types
91+
-
92+
identifier: match.alwaysTrue
93+
path: src/Utils/Image.php
94+
95+
# Image.php: Return type annotation conveys intent (ImageType constants are ints)
96+
-
97+
identifier: return.type
98+
path: src/Utils/Image.php
99+
count: 1
14100

15-
# PHPStan does not support RecursiveIteratorIterator proxying unknown method calls to inner iterator
16-
- '#RecursiveIteratorIterator::getSubPathName\(\)#'
101+
# Image.php: By-ref parameter type narrowing in isPercent()
102+
-
103+
identifier: parameterByRef.type
104+
path: src/Utils/Image.php
17105

18-
# static cannot be changed to maintain backward compatibility
19-
- '#Unsafe usage of new static\(\)#'
106+
# Iterables.php: Anonymous classes can't properly resolve template types from enclosing method
107+
-
108+
identifier: argument.templateType
109+
path: src/Utils/Iterables.php

src/Utils/Finder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function size(string $operator, ?int $size = null): static
288288

289289
[, $operator, $size, $unit] = $matches;
290290
$units = ['' => 1, 'k' => 1e3, 'm' => 1e6, 'g' => 1e9];
291-
$size *= $units[strtolower($unit)];
291+
$size = (float) $size * $units[strtolower($unit)];
292292
$operator = $operator ?: '=';
293293
}
294294

src/Utils/Strings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ public static function match(
547547
$pattern .= 'u';
548548
}
549549

550+
$m = [];
550551
if ($offset > strlen($subject)) {
551552
return null;
552553
} elseif (!self::pcre('preg_match', [$pattern, $subject, &$m, $flags, $offset])) {
@@ -588,6 +589,7 @@ public static function matchAll(
588589
$flags = PREG_OFFSET_CAPTURE | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0);
589590
return (function () use ($utf8, $captureOffset, $flags, $subject, $pattern, $offset) {
590591
$counter = 0;
592+
$m = null;
591593
while (
592594
$offset <= strlen($subject) - ($counter ? 1 : 0)
593595
&& self::pcre('preg_match', [$pattern, $subject, &$m, $flags, $offset])
@@ -611,6 +613,7 @@ public static function matchAll(
611613
? $captureOffset
612614
: ($captureOffset ? PREG_OFFSET_CAPTURE : 0) | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0) | ($patternOrder ? PREG_PATTERN_ORDER : 0);
613615

616+
$m = [];
614617
self::pcre('preg_match_all', [
615618
$pattern, $subject, &$m,
616619
($flags & PREG_PATTERN_ORDER) ? $flags : ($flags | PREG_SET_ORDER),

0 commit comments

Comments
 (0)