Skip to content

Commit 200d192

Browse files
authored
RegularExpressionPatternRule: support extended Nette\Utils\Strings
1 parent cacb698 commit 200d192

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Diff for: src/Rule/Nette/RegularExpressionPatternRule.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\Analyser\Scope;
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Rules\RuleErrorBuilder;
12+
use PHPStan\Type\ObjectType;
1213
use function in_array;
1314
use function sprintf;
1415
use function strtolower;
@@ -51,8 +52,8 @@ private function extractPatterns(StaticCall $staticCall, Scope $scope): array
5152
if (!$staticCall->class instanceof Node\Name || !$staticCall->name instanceof Node\Identifier) {
5253
return [];
5354
}
54-
$className = $scope->resolveName($staticCall->class);
55-
if ($className !== Strings::class) {
55+
$caller = $scope->resolveTypeByName($staticCall->class);
56+
if (!(new ObjectType(Strings::class))->isSuperTypeOf($caller)->yes()) {
5657
return [];
5758
}
5859
$methodName = strtolower((string) $staticCall->name);

Diff for: tests/Rule/Nette/RegularExpressionPatternRuleTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public function testValidRegexPatternAfter73(): void
7171
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1 in pattern: ~(~',
7272
26,
7373
],
74+
[
75+
sprintf('Regex pattern is invalid: Delimiter must not be %s in pattern: nok', $messagePart),
76+
36,
77+
],
7478
],
7579
);
7680
}

Diff for: tests/Rule/Nette/data/valid-regex-pattern.php

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
'~(~' => function () {},
3232
]
3333
);
34+
35+
class MyStrings extends \Nette\Utils\Strings {}
36+
MyStrings::replace('', 'nok', '');

0 commit comments

Comments
 (0)