Skip to content

Commit bf1f3e0

Browse files
committed
fixed PHPStan errors
1 parent 4c9d11e commit bf1f3e0

4 files changed

Lines changed: 95 additions & 9 deletions

File tree

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: 90 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,95 @@ 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+
50+
# Intentional pattern: assignment in condition with && operator
51+
-
52+
identifier: booleanAnd.rightAlwaysTrue
53+
path: src/Utils/Reflection.php
54+
55+
# Intentional pattern: ??= for caching filter results, variable is declared via reference
56+
-
57+
identifier: nullCoalesce.variable
58+
path: src/Utils/Finder.php
59+
60+
# Type test files: assertType() is the side effect, comparison warnings are expected
61+
-
62+
identifier: greater.alwaysTrue
63+
path: tests/types/utils-types.php
64+
65+
# Image.php: Callback signature intentionally simplified (doesn't use int parameter)
66+
-
67+
identifier: argument.type
68+
path: src/Utils/Image.php
69+
count: 1
70+
71+
# Image.php: Defensive validation even though phpDoc specifies positive-int
72+
-
73+
identifiers:
74+
- smaller.alwaysFalse
75+
- booleanOr.alwaysFalse
76+
path: src/Utils/Image.php
77+
78+
# Image.php: isset() check for type safety even though offset always exists
79+
-
80+
identifier: isset.offset
81+
path: src/Utils/Image.php
82+
83+
# Image.php: Match arms document all supported types
84+
-
85+
identifier: match.alwaysTrue
86+
path: src/Utils/Image.php
87+
88+
# Image.php: Return type annotation conveys intent (ImageType constants are ints)
89+
-
90+
identifier: return.type
91+
path: src/Utils/Image.php
92+
count: 1
1493

15-
# PHPStan does not support RecursiveIteratorIterator proxying unknown method calls to inner iterator
16-
- '#RecursiveIteratorIterator::getSubPathName\(\)#'
94+
# Image.php: By-ref parameter type narrowing in isPercent()
95+
-
96+
identifier: parameterByRef.type
97+
path: src/Utils/Image.php
1798

18-
# static cannot be changed to maintain backward compatibility
19-
- '#Unsafe usage of new static\(\)#'
99+
# Iterables.php: Anonymous classes can't properly resolve template types from enclosing method
100+
-
101+
identifier: argument.templateType
102+
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)