diff --git a/src/Analyser/ClassNode.php b/src/Analyser/ClassNode.php index 9dfa9cfe..0af55d3a 100644 --- a/src/Analyser/ClassNode.php +++ b/src/Analyser/ClassNode.php @@ -6,14 +6,13 @@ use function array_filter; use function preg_match; -use function str_ends_with; -use function str_starts_with; use function strrpos; use function substr; final class ClassNode { use MemberQueryTrait; + use NameQueryTrait; use NodeQueryTrait; use RecursiveParentsTrait; @@ -150,16 +149,6 @@ public function isClass(): bool return ! $this->isInterface && ! $this->isTrait && ! $this->isEnum; } - public function nameEndsWith(string $suffix): bool - { - return str_ends_with($this->shortName(), $suffix); - } - - public function nameStartsWith(string $prefix): bool - { - return str_starts_with($this->shortName(), $prefix); - } - public function nameMatches(string $pattern, bool $isFullName = false): bool { return (bool) preg_match($pattern, $isFullName ? $this->className : $this->shortName()); diff --git a/src/Analyser/FunctionNode.php b/src/Analyser/FunctionNode.php index d852b32d..cd2456ae 100644 --- a/src/Analyser/FunctionNode.php +++ b/src/Analyser/FunctionNode.php @@ -6,8 +6,6 @@ use function array_filter; use function preg_match; -use function str_ends_with; -use function str_starts_with; use function strrpos; use function substr; @@ -18,6 +16,7 @@ */ final readonly class FunctionNode { + use NameQueryTrait; use NodeQueryTrait; /** @var list */ @@ -58,16 +57,6 @@ public function shortName(): string : substr($this->functionName, $position + 1); } - public function nameEndsWith(string $suffix): bool - { - return str_ends_with($this->shortName(), $suffix); - } - - public function nameStartsWith(string $prefix): bool - { - return str_starts_with($this->shortName(), $prefix); - } - public function nameMatches(string $pattern, bool $isFullName = false): bool { return (bool) preg_match($pattern, $isFullName ? $this->functionName : $this->shortName()); diff --git a/src/Analyser/NameQueryTrait.php b/src/Analyser/NameQueryTrait.php new file mode 100644 index 00000000..76d26dd5 --- /dev/null +++ b/src/Analyser/NameQueryTrait.php @@ -0,0 +1,28 @@ +shortName(), $suffix); + } + + public function nameStartsWith(string $prefix): bool + { + return str_starts_with($this->shortName(), $prefix); + } +}