| Total Complexity | 13 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Coverage | 96% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | final class EnumLocator extends AbstractLocator implements EnumsInterface |
||
| 13 | { |
||
| 14 | public const INJECTOR = EnumLocatorInjector::class; |
||
| 15 | |||
| 16 | 7 | public function getEnums(object|string|null $target = null): array |
|
| 17 | { |
||
| 18 | 7 | if (!empty($target)) { |
|
| 19 | 4 | $target = new \ReflectionClass($target); |
|
| 20 | } |
||
| 21 | |||
| 22 | 7 | $result = []; |
|
| 23 | 7 | foreach ($this->availableEnums() as $enum) { |
|
| 24 | try { |
||
| 25 | 7 | $reflection = $this->enumReflection($enum); |
|
| 26 | 6 | } catch (LocatorException $e) { |
|
| 27 | 6 | if ($this->debug) { |
|
| 28 | throw $e; |
||
| 29 | } |
||
| 30 | |||
| 31 | //Ignoring |
||
| 32 | 6 | continue; |
|
| 33 | } |
||
| 34 | |||
| 35 | 7 | if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
| 36 | 4 | continue; |
|
| 37 | } |
||
| 38 | |||
| 39 | 7 | $result[$reflection->getName()] = $reflection; |
|
| 40 | } |
||
| 41 | |||
| 42 | 7 | return $result; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Enums available in finder scope. |
||
| 47 | * |
||
| 48 | * @return class-string[] |
||
|
|
|||
| 49 | */ |
||
| 50 | 7 | protected function availableEnums(): array |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Check if given enum targeted by locator. |
||
| 63 | * |
||
| 64 | * @param \ReflectionClass|null $target |
||
| 65 | */ |
||
| 66 | 7 | protected function isTargeted(\ReflectionEnum $enum, \ReflectionClass $target = null): bool |
|
| 79 | } |
||
| 80 | } |
||
| 81 |