Total Complexity | 12 |
Total Lines | 64 |
Duplicated Lines | 0 % |
Coverage | 90% |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
9 | trait ControllerAnnotationExtractorTrait |
||
10 | { |
||
11 | /** |
||
12 | * @return Reader |
||
13 | */ |
||
14 | abstract protected function getAnnotationReader(): Reader; |
||
15 | |||
16 | /** |
||
17 | * @param callable $controller |
||
18 | * @param string $annotationClass |
||
19 | * |
||
20 | * @return null|object |
||
21 | */ |
||
22 | 20 | protected function getClassAnnotationFromController(callable $controller, string $annotationClass) |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param callable $controller |
||
36 | * @param string $annotationClass |
||
37 | * |
||
38 | * @throws \ReflectionException When $controller method does not exist |
||
39 | * |
||
40 | * @return null|object |
||
41 | */ |
||
42 | 22 | protected function getMethodAnnotationFromController(callable $controller, string $annotationClass) |
|
43 | { |
||
44 | 22 | if (\is_array($controller) |
|
45 | 22 | && isset($controller[1]) |
|
46 | 22 | && \is_object($objectToReflect = $this->getObjectToReflect($controller)) |
|
47 | ) { |
||
48 | 22 | return $this->getAnnotationReader()->getMethodAnnotation( |
|
49 | 22 | new \ReflectionMethod($objectToReflect, $controller[1]), |
|
50 | 22 | $annotationClass |
|
51 | ); |
||
52 | } |
||
53 | |||
54 | return null; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param callable $controller |
||
59 | * |
||
60 | * @return null|object |
||
61 | */ |
||
62 | 26 | protected function getObjectToReflect(callable $controller) |
|
73 | } |
||
74 | } |
||
75 |