Completed
Push — master ( c8c0c1...47af09 )
by Jakub
01:44
created

Reader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
eloc 12
c 2
b 0
f 1
dl 0
loc 36
rs 10
ccs 14
cts 14
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasAnnotation() 0 8 3
A getAnnotation() 0 9 3
A registerEngine() 0 3 1
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 1
    public function registerEngine(IAnnotationsReaderEngine $engine): void
21
    {
22 1
        $this->engines[] = $engine;
23 1
    }
24
25
    /**
26
     * @param string|object $class
27
     */
28 1
    public function hasAnnotation(string $name, $class, string $method = null): bool
29
    {
30 1
        foreach ($this->engines as $engine) {
31 1
            if ($engine->hasAnnotation($name, $class, $method)) {
32 1
                return true;
33
            }
34
        }
35 1
        return false;
36
    }
37
38
    /**
39
     * @param string|object $class
40
     * @return mixed
41
     */
42 1
    public function getAnnotation(string $name, $class, string $method = null)
43
    {
44 1
        foreach ($this->engines as $engine) {
45 1
            $value = $engine->getAnnotation($name, $class, $method);
46 1
            if ($value !== null) {
47 1
                return $value;
48
            }
49
        }
50 1
        return null;
51
    }
52
}
53