Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 1 addition & 12 deletions src/Analyser/ClassNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
13 changes: 1 addition & 12 deletions src/Analyser/FunctionNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,6 +16,7 @@
*/
final readonly class FunctionNode
{
use NameQueryTrait;
use NodeQueryTrait;

/** @var list<string> */
Expand Down Expand Up @@ -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());
Expand Down
28 changes: 28 additions & 0 deletions src/Analyser/NameQueryTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Boundwize\StructArmed\Analyser;

use function str_ends_with;
use function str_starts_with;

/**
* Short-name query helpers shared by {@see ClassNode} and {@see FunctionNode}.
*
* @internal
*/
trait NameQueryTrait
{
abstract public function shortName(): string;

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);
}
}