Skip to content

Commit e48c4c4

Browse files
committed
RegularExpressionPatternRule: support extended Strings
1 parent cacb698 commit e48c4c4

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/Rule/Nette/RegularExpressionPatternRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ private function extractPatterns(StaticCall $staticCall, Scope $scope): array
5151
if (!$staticCall->class instanceof Node\Name || !$staticCall->name instanceof Node\Identifier) {
5252
return [];
5353
}
54-
$className = $scope->resolveName($staticCall->class);
55-
if ($className !== Strings::class) {
54+
$caller = $scope->resolveTypeByName($staticCall->class);
55+
if ($caller->getClassReflection() === null || !$caller->getClassReflection()->is(Strings::class)) {
5656
return [];
5757
}
5858
$methodName = strtolower((string) $staticCall->name);

tests/Rule/Nette/RegularExpressionPatternRuleTest.php

Lines changed: 4 additions & 0 deletions
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+
'Regex pattern is invalid: Delimiter must not be alphanumeric, backslash, or NUL in pattern: nok',
76+
36,
77+
],
7478
],
7579
);
7680
}

tests/Rule/Nette/data/valid-regex-pattern.php

Lines changed: 3 additions & 0 deletions
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)