| Total Complexity | 8 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 19 | final class PhpAttributesEngine implements \MyTester\IAnnotationsReaderEngine |
||
| 20 | { |
||
| 21 | 1 | public function hasAnnotation(string $name, string|object $class, string $method = null): bool |
|
| 22 | { |
||
| 23 | 1 | return count($this->getReflection($class, $method)->getAttributes($this->getClassName($name))) > 0; |
|
| 24 | } |
||
| 25 | |||
| 26 | 1 | public function getAnnotation(string $name, string|object $class, string $method = null): mixed |
|
| 27 | { |
||
| 28 | 1 | $attributes = $this->getReflection($class, $method)->getAttributes($this->getClassName($name)); |
|
| 29 | 1 | if (count($attributes) === 0) { |
|
| 30 | 1 | return null; |
|
| 31 | } |
||
| 32 | /** @var BaseAttribute $attribute */ |
||
| 33 | 1 | $attribute = $attributes[0]->newInstance(); |
|
| 34 | 1 | return $attribute->value; |
|
| 35 | } |
||
| 36 | |||
| 37 | 1 | private function getClassName(string $baseName): string |
|
| 38 | { |
||
| 39 | 1 | return "MyTester\\Attributes\\" . Strings::firstUpper($baseName); |
|
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @throws ReflectionException |
||
| 44 | */ |
||
| 45 | 1 | private function getReflection(string|object $class, string $method = null): ReflectionClass|ReflectionMethod |
|
| 53 | } |
||
| 54 | } |
||
| 55 |