diff --git a/src/Rule/Nette/RegularExpressionPatternRule.php b/src/Rule/Nette/RegularExpressionPatternRule.php index bee94ea..9a9638c 100644 --- a/src/Rule/Nette/RegularExpressionPatternRule.php +++ b/src/Rule/Nette/RegularExpressionPatternRule.php @@ -9,6 +9,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; +use PHPStan\Type\ObjectType; use function in_array; use function sprintf; use function strtolower; @@ -51,8 +52,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 (!(new ObjectType(Strings::class))->isSuperTypeOf($caller)->yes()) { return []; } $methodName = strtolower((string) $staticCall->name); diff --git a/tests/Rule/Nette/RegularExpressionPatternRuleTest.php b/tests/Rule/Nette/RegularExpressionPatternRuleTest.php index 86ae8bd..88d222c 100644 --- a/tests/Rule/Nette/RegularExpressionPatternRuleTest.php +++ b/tests/Rule/Nette/RegularExpressionPatternRuleTest.php @@ -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, + ], ], ); } diff --git a/tests/Rule/Nette/data/valid-regex-pattern.php b/tests/Rule/Nette/data/valid-regex-pattern.php index d76813f..a039d32 100644 --- a/tests/Rule/Nette/data/valid-regex-pattern.php +++ b/tests/Rule/Nette/data/valid-regex-pattern.php @@ -31,3 +31,6 @@ '~(~' => function () {}, ] ); + +class MyStrings extends \Nette\Utils\Strings {} +MyStrings::replace('', 'nok', '');