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

ChannelManager::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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