Completed
Push — master ( 947cff...af97d0 )
by Nikola
04:03
created

Channels::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Notifier\Channel;
6
7
use ArrayIterator;
8
use IteratorAggregate;
9
use Notifier\Channel\Exception\ChannelNotFound;
10
use Traversable;
11
12
class Channels implements IteratorAggregate
13
{
14
    /** @var Channel[] */
15
    protected $channels;
16
17 3
    public function __construct(Channel ...$channels)
18
    {
19 3
        foreach ($channels as $channel) {
20 3
            $this->channels[$channel->getName()] = $channel;
21
        }
22 3
    }
23
24 2
    public function get(string $channelName): Channel
25
    {
26 2
        if (!isset($this->channels[$channelName])) {
27 1
            throw ChannelNotFound::byName($channelName);
28
        }
29
30 1
        return $this->channels[$channelName];
31
    }
32
33
    /**
34
     * @return Traversable|Channel[]
35
     */
36 1
    public function getIterator()
37
    {
38 1
        return new ArrayIterator($this->channels);
39
    }
40
}
41