Completed
Push — master ( f5244f...96e614 )
by Vladimir
02:50
created

ChannelManager::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Channels;
6
7
class ChannelManager
8
{
9
    /** @var array */
10
    private $channels;
11
12
    /**
13
     * Add channel.
14
     *
15
     * @param string $name
16
     * @param array  $parameters
17
     */
18 3
    public function add(string $name, array $parameters): void
19
    {
20 3
        $this->channels[$name] = $parameters;
21 3
    }
22
23
    /**
24
     * Get all channels.
25
     *
26
     * @return array
27
     */
28 1
    public function all(): array
29
    {
30 1
        return $this->channels;
31
    }
32
33
    /**
34
     * Create channel.
35
     *
36
     * @param string $name
37
     *
38
     * @return Channel
39
     * @throws ChannelNotFound
40
     */
41 3
    public function create(string $name): Channel
42
    {
43 3
        if (!isset($this->channels[$name])) {
44 1
            throw new ChannelNotFound('Channel `'.$name.'` not found.');
45
        }
46
47 2
        $data = collect($this->channels[$name]);
48
49 2
        $driver = $data->get('driver');
50 2
        $parameters = $data->except('driver')->toArray();
51
52 2
        return new Channel($name, $driver, $parameters);
53
    }
54
}
55