From b8a42182f1abe14c1b3dbcc49b6f95a98ded81c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 27 May 2025 10:22:45 +0200 Subject: [PATCH] feat: import namespaces over src --- src/PHPStan/InvalidRegexPatternRule.php | 3 ++- src/PHPStan/UnsafeStrictGroupsCallRule.php | 3 ++- src/PcreException.php | 4 +++- src/Regex.php | 6 ++++-- src/UnexpectedNullMatchException.php | 4 +++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/PHPStan/InvalidRegexPatternRule.php b/src/PHPStan/InvalidRegexPatternRule.php index 8a05fb2..57e31fd 100644 --- a/src/PHPStan/InvalidRegexPatternRule.php +++ b/src/PHPStan/InvalidRegexPatternRule.php @@ -2,6 +2,7 @@ namespace Composer\Pcre\PHPStan; +use PhpParser\Node\Identifier; use Composer\Pcre\Preg; use Composer\Pcre\Regex; use Composer\Pcre\PcreException; @@ -58,7 +59,7 @@ private function extractPatterns(StaticCall $node, Scope $scope): array if (!$isRegex && !$isPreg) { return []; } - if (!$node->name instanceof Node\Identifier || !Preg::isMatch('{^(match|isMatch|grep|replace|split)}', $node->name->name)) { + if (!$node->name instanceof Identifier || !Preg::isMatch('{^(match|isMatch|grep|replace|split)}', $node->name->name)) { return []; } diff --git a/src/PHPStan/UnsafeStrictGroupsCallRule.php b/src/PHPStan/UnsafeStrictGroupsCallRule.php index 5bced50..9177718 100644 --- a/src/PHPStan/UnsafeStrictGroupsCallRule.php +++ b/src/PHPStan/UnsafeStrictGroupsCallRule.php @@ -2,6 +2,7 @@ namespace Composer\Pcre\PHPStan; +use PhpParser\Node\Identifier; use Composer\Pcre\Preg; use Composer\Pcre\Regex; use PhpParser\Node; @@ -48,7 +49,7 @@ public function processNode(Node $node, Scope $scope): array if (!$isRegex && !$isPreg) { return []; } - if (!$node->name instanceof Node\Identifier || !in_array($node->name->name, ['matchStrictGroups', 'isMatchStrictGroups', 'matchAllStrictGroups', 'isMatchAllStrictGroups'], true)) { + if (!$node->name instanceof Identifier || !in_array($node->name->name, ['matchStrictGroups', 'isMatchStrictGroups', 'matchAllStrictGroups', 'isMatchAllStrictGroups'], true)) { return []; } diff --git a/src/PcreException.php b/src/PcreException.php index 23d9327..88dc2b6 100644 --- a/src/PcreException.php +++ b/src/PcreException.php @@ -11,7 +11,9 @@ namespace Composer\Pcre; -class PcreException extends \RuntimeException +use RuntimeException; + +class PcreException extends RuntimeException { /** * @param string $function diff --git a/src/Regex.php b/src/Regex.php index 038cf06..454a73d 100644 --- a/src/Regex.php +++ b/src/Regex.php @@ -11,6 +11,8 @@ namespace Composer\Pcre; +use InvalidArgumentException; + class Regex { /** @@ -163,14 +165,14 @@ public static function replaceCallbackArray(array $pattern, $subject, int $limit private static function checkOffsetCapture(int $flags, string $useFunctionName): void { if (($flags & PREG_OFFSET_CAPTURE) !== 0) { - throw new \InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the return type, use '.$useFunctionName.'() instead'); + throw new InvalidArgumentException('PREG_OFFSET_CAPTURE is not supported as it changes the return type, use '.$useFunctionName.'() instead'); } } private static function checkSetOrder(int $flags): void { if (($flags & PREG_SET_ORDER) !== 0) { - throw new \InvalidArgumentException('PREG_SET_ORDER is not supported as it changes the return type'); + throw new InvalidArgumentException('PREG_SET_ORDER is not supported as it changes the return type'); } } } diff --git a/src/UnexpectedNullMatchException.php b/src/UnexpectedNullMatchException.php index f123828..1d51091 100644 --- a/src/UnexpectedNullMatchException.php +++ b/src/UnexpectedNullMatchException.php @@ -11,10 +11,12 @@ namespace Composer\Pcre; +use LogicException; + class UnexpectedNullMatchException extends PcreException { public static function fromFunction($function, $pattern) { - throw new \LogicException('fromFunction should not be called on '.self::class.', use '.PcreException::class); + throw new LogicException('fromFunction should not be called on '.self::class.', use '.PcreException::class); } }