Completed
Pull Request — master (#1)
by
unknown
01:35
created

Aggregator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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
     * Set driver instance.
16
     *
17
     * @param  string  $name
18
     * @param  mixed  $driver
19
     * @return void
20
     *
21
     * @throws \DeGraciaMathieu\Manager\Exceptions\DriverOverwrittenException
22
     */
23 3
    public function set(string $name, $driver)
24
    {
25 3
        if ($this->has($name)) {
26 1
            throw new DriverOverwrittenException("Driver [$name] already registered.");
27
        }
28
29 3
        $this->drivers[$name] = $driver;
30 3
    }
31
32
    /**
33
     * Get driver instance.
34
     *
35
     * @param  string  $name
36
     * @return mixed
37
     */
38 2
    public function get(string $name)
39
    {
40 2
        return $this->drivers[$name];
41
    }
42
43
    /**
44
     * Check if driver instance exists.
45
     *
46
     * @param  string  $name
47
     * @return boolean
48
     */
49 3
    public function has(string $name)
50
    {
51 3
        return array_key_exists($name, $this->drivers);
52
    }
53
54
    /**
55
     * Get all drivers instance.
56
     *
57
     * @return array
58
     */
59 1
    public function all()
60
    {
61 1
        return $this->drivers;
62
    }
63
}
64