Conditions | 5 |
Paths | 8 |
Total Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
9 | function toXOrNotToX(string $annotation, string $callable, Reader $annotationReader = null, bool $checkClass = true): bool |
||
10 | { |
||
11 | 4 | if (!($annotationReader instanceof Reader)) { |
|
12 | 4 | $annotationReader = new AnnotationReader(); |
|
13 | } |
||
14 | |||
15 | 4 | list($class, $method) = \explode('::', $callable); |
|
16 | |||
17 | 4 | $annotations = (new Collection($annotationReader->getMethodAnnotations((new \ReflectionClass($class))->getMethod($method)))) |
|
18 | ->indexBy(function (object $annotation) { |
||
19 | 1 | return \get_class($annotation); |
|
20 | 4 | })->toArray(); |
|
21 | |||
22 | 4 | if (isset($annotations[$annotation])) { |
|
23 | 1 | return true; |
|
24 | } |
||
25 | |||
26 | 3 | if ($checkClass === false) { |
|
27 | 1 | return false; |
|
28 | } |
||
29 | |||
30 | 2 | $annotations = (new Collection($annotationReader->getClassAnnotations(new \ReflectionClass($class)))) |
|
31 | ->indexBy(function (object $annotation) { |
||
32 | 1 | return \get_class($annotation); |
|
33 | 2 | })->toArray(); |
|
34 | |||
35 | 2 | if (isset($annotations[$annotation])) { |
|
36 | 1 | return true; |
|
37 | } |
||
38 | |||
39 | 1 | return false; |
|
40 | } |
||
41 |