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

DataProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
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
?>