Passed
Push — master ( 04a9d5...864e2a )
by Mike
06:31
created

TwigExtensionCollection::next()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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