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

Reader::hasAnnotation()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 4
c 1
b 0
f 1
nc 3
nop 3
dl 0
loc 7
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace MyTester\Annotations;
5
6
use MyTester\IAnnotationsReaderEngine;
7
8
/**
9
 * Annotations reader
10
 *
11
 * @author Jakub Konečný
12
 * @internal
13
 */
14
final class Reader {
15
  /** @var IAnnotationsReaderEngine[] */
16
  private array $engines = [];
17
18
  public function registerEngine(IAnnotationsReaderEngine $engine): void {
19
    $this->engines[] = $engine;
20
  }
21
22
  /**
23
   * @param string|object $class
24
   */
25
  public function hasAnnotation(string $name, $class, string $method = null): bool {
26
    foreach($this->engines as $engine) {
27
      if($engine->hasAnnotation($name, $class, $method)) {
28
        return true;
29
      }
30
    }
31
    return false;
32
  }
33
34
  /**
35
   * @param string|object $class
36
   * @return mixed
37
   */
38
  public function getAnnotation(string $name, $class, string $method = null) {
39
    foreach($this->engines as $engine) {
40
      $value = $engine->getAnnotation($name, $class, $method);
41
      if($value !== null) {
42
        return $value;
43
      }
44
    }
45
    return null;
46
  }
47
}
48
?>