Completed
Push — master ( 2c1133...a0bd3c )
by Mike
03:11
created

HelperCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 9
eloc 12
dl 0
loc 72
c 0
b 0
f 0
ccs 17
cts 21
cp 0.8095
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A valid() 0 3 1
A count() 0 3 1
A key() 0 3 1
A rewind() 0 3 1
A current() 0 3 1
A add() 0 3 1
A next() 0 3 1
1
<?php
2
3
4
namespace Xervice\Core\HelperClass;
5
6
7
class HelperCollection implements \Iterator, \Countable
8
{
9
    /**
10
     * @var \Xervice\Core\HelperClass\HelperInterface[]
11
     */
12
    private $collection;
13
14
    /**
15
     * @var int
16
     */
17
    private $position;
18
19
    /**
20
     * Collection constructor.
21
     *
22
     * @param \Xervice\Core\HelperClass\HelperInterface[] $collection
23
     */
24 3
    public function __construct(array $collection)
25
    {
26 3
        foreach ($collection as $validator) {
27 3
            $this->add($validator);
28
        }
29 3
    }
30
31
    /**
32
     * @param \Xervice\Core\HelperClass\HelperInterface $validator
33
     */
34 3
    public function add(HelperInterface $validator): void
35
    {
36 3
        $this->collection[] = $validator;
37 3
    }
38
39
    /**
40
     * @return \Xervice\Core\HelperClass\HelperInterface
41
     */
42 2
    public function current(): HelperInterface
43
    {
44 2
        return $this->collection[$this->position];
45
    }
46
47 1
    public function next(): void
48
    {
49 1
        $this->position++;
50 1
    }
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
}