Total Complexity | 13 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
9 | final class PhpAttributesEngine implements \MyTester\IAnnotationsReaderEngine { |
||
10 | public function hasAnnotation(string $name, $class, string $method = null): bool { |
||
11 | if(!$this->isAvailable()) { |
||
12 | return false; |
||
13 | } |
||
14 | $attributeClassName = $this->getClassName($name); |
||
15 | if($method !== null) { |
||
16 | $reflection = new ReflectionMethod(is_object($class) ? get_class($class) : $class, $method); |
||
17 | } else { |
||
18 | $reflection = new \ReflectionClass(is_object($class) ? get_class($class) : $class); |
||
19 | } |
||
20 | return count($reflection->getAttributes($attributeClassName)) > 0; |
||
1 ignored issue
–
show
|
|||
21 | } |
||
22 | |||
23 | public function getAnnotation(string $name, $class, string $method = null) { |
||
24 | if(!$this->isAvailable()) { |
||
25 | return null; |
||
26 | } |
||
27 | $attributeClassName = $this->getClassName($name); |
||
28 | if($method !== null) { |
||
29 | $reflection = new ReflectionMethod(is_object($class) ? get_class($class) : $class, $method); |
||
30 | } else { |
||
31 | $reflection = new \ReflectionClass(is_object($class) ? get_class($class) : $class); |
||
32 | } |
||
33 | $attributes = $reflection->getAttributes($attributeClassName); |
||
34 | if(count($attributes) === 0) { |
||
35 | return null; |
||
36 | } |
||
37 | return $attributes[0]; |
||
38 | } |
||
39 | |||
40 | private function isAvailable(): bool { |
||
42 | } |
||
43 | |||
44 | private function getClassName(string $baseName): string { |
||
46 | } |
||
47 | } |
||
48 | ?> |