AnnotationCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 11
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findOneBy() 0 5 1
A __construct() 0 3 1
A findAllBy() 0 7 1
A getOneBy() 0 7 2
1
<?php
2
3
namespace Er1z\FakeMock\Annotations;
4
5
class AnnotationCollection
6
{
7
    /**
8
     * @var array
9
     */
10
    private $annotations;
11
12 159
    public function __construct($annotations = [])
13
    {
14 159
        $this->annotations = $annotations;
15 159
    }
16
17 4
    public function getOneBy($class)
18
    {
19 4
        if ($result = $this->findOneBy($class)) {
20 4
            return $result;
21
        }
22
23 4
        throw new \InvalidArgumentException(sprintf('Annotation %s not found in collection', $class));
24
    }
25
26 14
    public function findOneBy($class)
27
    {
28 14
        $result = array_values($this->findAllBy($class))[0] ?? null;
29
30 14
        return $result;
31
    }
32
33 77
    public function findAllBy($class)
34
    {
35
        $result = array_filter($this->annotations, function ($a) use ($class) {
36 66
            return $a instanceof $class;
37 77
        });
38
39 77
        return array_values($result);
40
    }
41
}
42