Conditions | 6 |
Paths | 9 |
Total Lines | 23 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 6.9157 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
30 | 1 | public function getData(object $class, string $method): array { |
|
31 | 1 | $reflection = new ReflectionMethod($class, $method); |
|
32 | 1 | if($reflection->getNumberOfParameters() < 1) { |
|
33 | 1 | return []; |
|
34 | } |
||
35 | 1 | $dataProvider = $this->annotationsReader->getAnnotation(static::PROVIDER_ANNOTATION_NAME, $class, $method); |
|
36 | 1 | if(is_string($dataProvider)) { |
|
37 | 1 | $className = $reflection->getDeclaringClass()->getName(); |
|
38 | try { |
||
39 | 1 | $reflection = new ReflectionMethod($class, $dataProvider); |
|
40 | 1 | if(!$reflection->isPublic()) { |
|
41 | throw new InvalidDataProviderException("Method $className::$dataProvider is not public."); |
||
42 | } |
||
43 | 1 | $result = call_user_func([$class, $dataProvider]); |
|
44 | 1 | if(!is_array($result)) { |
|
45 | throw new InvalidDataProviderException("Method $className::$dataProvider has to return an array."); |
||
46 | } |
||
47 | 1 | return $result; |
|
48 | } catch(\ReflectionException $e) { |
||
49 | throw new InvalidDataProviderException("Method $className::$dataProvider does not exist.", 0, $e); |
||
50 | } |
||
51 | } |
||
52 | return []; |
||
53 | } |
||
55 | ?> |