Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Rule/Nette/RegularExpressionPatternRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ private function extractPatterns(StaticCall $staticCall, Scope $scope): array
if (!$staticCall->class instanceof Node\Name || !$staticCall->name instanceof Node\Identifier) {
return [];
}
$className = $scope->resolveName($staticCall->class);
if ($className !== Strings::class) {
$caller = $scope->resolveTypeByName($staticCall->class);
if ($caller->getClassReflection() === null || !$caller->getClassReflection()->is(Strings::class)) {
return [];
}
$methodName = strtolower((string) $staticCall->name);
Expand Down
4 changes: 4 additions & 0 deletions tests/Rule/Nette/RegularExpressionPatternRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function testValidRegexPatternAfter73(): void
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1 in pattern: ~(~',
26,
],
[
sprintf('Regex pattern is invalid: Delimiter must not be %s in pattern: nok', $messagePart),
36,
],
],
);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Rule/Nette/data/valid-regex-pattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
'~(~' => function () {},
]
);

class MyStrings extends \Nette\Utils\Strings {}
MyStrings::replace('', 'nok', '');