Completed
Push — master ( 421647...4d40dc )
by
unknown
04:04
created

ChannelManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A all() 0 4 1
A get() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Channels;
6
7
use FondBot\Channels\Exceptions\ChannelNotFound;
8
9
class ChannelManager
10
{
11
    /** @var array */
12
    private $channels = [];
13
14
    /**
15
     * Register channels.
16
     *
17
     * @param array $channels
18
     */
19 2
    public function register(array $channels): void
20
    {
21 2
        $this->channels = $channels;
22 2
    }
23
24
    /**
25
     * Get all channels.
26
     *
27
     * @return array
28
     */
29 1
    public function all(): array
30
    {
31 1
        return $this->channels;
32
    }
33
34
    /**
35
     * Get channel by name.
36
     *
37
     * @param string $name
38
     *
39
     * @return Channel
40
     * @throws ChannelNotFound
41
     */
42 2
    public function get(string $name): Channel
43
    {
44 2
        if (!array_has($this->channels, $name)) {
45 1
            throw new ChannelNotFound('Channel `'.$name.'` not found.');
46
        }
47
48 1
        $data = collect($this->channels[$name]);
49
50 1
        $driver = $data->get('driver');
51 1
        $parameters = $data->except('driver')->toArray();
52
53 1
        return new Channel($name, $driver, $parameters);
54
    }
55
}
56