Completed
Push — master ( d83119...6e6854 )
by Jakub
01:39
created

DataProvider::getData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 5
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 8
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace MyTester;
5
6
use MyTester\Annotations\Reader;
7
use ReflectionMethod;
8
9
/**
10
 * DataProvider
11
 *
12
 * @author Jakub Konečný
13
 * @internal
14
 */
15
final class DataProvider {
16
  use \Nette\SmartObject;
17
18
  public const ANNOTATION_NAME = "data";
19
20
  private Reader $annotationsReader;
21
22
  public function __construct(Reader $annotationsReader) {
23
    $this->annotationsReader = $annotationsReader;
24
  }
25
26
  public function getData(string $class, string $method): array {
27
    $reflection = new ReflectionMethod($class, $method);
28
    if($reflection->getNumberOfParameters() < 1) {
29
      return [];
30
    }
31
    /** @var mixed $value */
32
    $value = $this->annotationsReader->getAnnotation(static::ANNOTATION_NAME, $class, $method);
33
    return (array) $value;
34
  }
35
}
36
?>