Passed
Push — master ( 68b437...eb1a97 )
by Mike
08:08
created

PathCollection::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Twig\Business\Model\Path;
6
7
8
use Xervice\Twig\Business\Dependency\Path\PathProviderInterface;
9
10
class PathCollection implements \Iterator, \Countable
11
{
12
    /**
13
     * @var \Xervice\Twig\Business\Dependency\Path\PathProviderInterface[]
14
     */
15
    private $collection;
16
17
    /**
18
     * @var int
19
     */
20
    private $position;
21
22
    /**
23
     * Collection constructor.
24
     *
25
     * @param \Xervice\Twig\Business\Dependency\Path\PathProviderInterface[] $collection
26
     */
27 2
    public function __construct(array $collection)
28
    {
29 2
        foreach ($collection as $validator) {
30 2
            $this->add($validator);
31
        }
32 2
    }
33
34
    /**
35
     * @param \Xervice\Twig\Business\Dependency\Path\PathProviderInterface $validator
36
     */
37 2
    public function add(PathProviderInterface $validator): void
38
    {
39 2
        $this->collection[] = $validator;
40 2
    }
41
42
    /**
43
     * @return \Xervice\Twig\Business\Dependency\Path\PathProviderInterface
44
     */
45 2
    public function current(): PathProviderInterface
46
    {
47 2
        return $this->collection[$this->position];
48
    }
49
50 2
    public function next(): void
51
    {
52 2
        $this->position++;
53 2
    }
54
55
    /**
56
     * @return int
57
     */
58
    public function key(): int
59
    {
60
        return $this->position;
61
    }
62
63
    /**
64
     * @return bool
65
     */
66 2
    public function valid(): bool
67
    {
68 2
        return isset($this->collection[$this->position]);
69
    }
70
71 2
    public function rewind(): void
72
    {
73 2
        $this->position = 0;
74 2
    }
75
76
    /**
77
     * @return int
78
     */
79
    public function count(): int
80
    {
81
        return \count($this->collection);
82
    }
83
}