| Total Complexity | 9 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE), NamedArgumentConstructor] |
||
| 17 | final class TargetClass implements ListenerDefinitionInterface |
||
| 18 | { |
||
| 19 | use TargetTrait; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param class-string $class |
||
|
|
|||
| 23 | * @param non-empty-string|null $scope |
||
| 24 | */ |
||
| 25 | public function __construct( |
||
| 26 | public readonly string $class, |
||
| 27 | public readonly ?string $scope = null, |
||
| 28 | ) { |
||
| 29 | } |
||
| 30 | |||
| 31 | public function filter(array $classes): \Generator |
||
| 32 | { |
||
| 33 | $target = new \ReflectionClass($this->class); |
||
| 34 | |||
| 35 | foreach ($classes as $class) { |
||
| 36 | if (!$target->isTrait()) { |
||
| 37 | if ($class->isSubclassOf($target) || $class->getName() === $target->getName()) { |
||
| 38 | yield $class->getName(); |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | // Checking using traits |
||
| 44 | if (\in_array($target->getName(), $this->fetchTraits($class->getName()))) { |
||
| 45 | yield $class->getName(); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | public function getCacheKey(): string |
||
| 51 | { |
||
| 52 | return \md5($this->class . $this->scope); |
||
| 53 | } |
||
| 54 | |||
| 55 | public function getScope(): ?string |
||
| 58 | } |
||
| 59 | } |
||
| 60 |