ListenerCollection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 80.95%

Importance

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

8 Methods

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