Channels::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Notifier\Channel;
6
7
use ArrayIterator;
8
use IteratorAggregate;
9
use Notifier\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