Completed
Push — master ( 1f684d...57b871 )
by Mike
02:29
created

ExchangeCollection::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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