Passed
Push — master ( d6f237...737295 )
by Jakub
01:43
created

Reader::getAnnotation()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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