Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
MsgCollection | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
addMsg | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
count | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMessages | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIterator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
5 | */ |
6 | |
7 | declare(strict_types=1); |
8 | |
9 | namespace pvc\msg; |
10 | |
11 | use ArrayIterator; |
12 | use Countable; |
13 | use IteratorAggregate; |
14 | use pvc\interfaces\msg\MsgInterface; |
15 | |
16 | /** |
17 | * Class MsgCollection |
18 | * @implements IteratorAggregate<int, MsgInterface> |
19 | */ |
20 | class MsgCollection implements IteratorAggregate, Countable |
21 | { |
22 | /** |
23 | * @var array<int, MsgInterface> |
24 | */ |
25 | protected array $messages = []; |
26 | |
27 | /** |
28 | * @function addMsg |
29 | * @param MsgInterface $msg |
30 | */ |
31 | public function addMsg(MsgInterface $msg): void |
32 | { |
33 | $this->messages[] = $msg; |
34 | } |
35 | |
36 | /** |
37 | * @function count |
38 | * @return int |
39 | */ |
40 | public function count(): int |
41 | { |
42 | return count($this->messages); |
43 | } |
44 | |
45 | /** |
46 | * getMessages |
47 | * @return MsgInterface[] |
48 | */ |
49 | public function getMessages(): array |
50 | { |
51 | return $this->messages; |
52 | } |
53 | |
54 | /** |
55 | * getIterator |
56 | * @return ArrayIterator<int, MsgInterface> |
57 | */ |
58 | public function getIterator(): ArrayIterator |
59 | { |
60 | return new ArrayIterator($this->messages); |
61 | } |
62 | } |