Test Failed
Pull Request — master (#2)
by
unknown
01:44
created

Aggregator::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.032
1
<?php
2
3
namespace DeGraciaMathieu\Manager;
4
5
use DeGraciaMathieu\Manager\Exceptions\DriverOverwrittenException;
6
7
final class Aggregator
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $drivers;
13
14
    /**
15
     * Welcome
16
     */
17 3
    public function __construct()
18
    {
19 3
        $this->drivers = [];
20 3
    }
21
22
    /**
23
     * Set driver instance
24
     *
25
     * @param string $name
26
     * @param mixed $driver
27
     * @throws \DeGraciaMathieu\Manager\Exceptions\DriverOverwrittenException
28
     *
29
     * @return void
30
     */
31 2
    public function set(string $name, $driver)
32
    {
33 2
        if ($this->has($name)) {
34
            throw new DriverOverwrittenException('Driver [' . $name . '] already registered.');
35
        }
36
37 2
        $this->drivers[$name] = $driver;
38 2
    }
39
40
    /**
41
     * Get driver instance
42
     *
43
     * @param  string  $name
44
     * 
45
     * @return mixed
46
     */
47 2
    public function get(string $name)
48
    {
49 2
        return $this->drivers[$name];
50
    }
51
52
    /**
53
     * Check if driver instance exists
54
     *
55
     * @param  string  $name
56
     * 
57
     * @return boolean
58
     */
59 2
    public function has(string $name)
60
    {
61 2
        return array_key_exists($name, $this->drivers);
62
    }   
63
64
    /**
65
     * Get all drivers instance
66
     *
67
     * @return array
68
     */
69 1
    public function all(): array
70
    {
71 1
        return $this->drivers;
72
    }           
73
}
74