Completed
Push — master ( 1e521f...10533f )
by Vladimir
02:32
created

Driver::initialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
ccs 0
cts 6
cp 0
crap 6
rs 9.4285
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Drivers;
6
7
use Illuminate\Support\Collection;
8
use FondBot\Contracts\Driver as DriverContract;
9
10
abstract class Driver implements DriverContract
11
{
12
    /** @var Collection */
13
    protected $parameters;
14
15
    /**
16
     * Get driver short name.
17
     *
18
     * This name is used as an alias for configuration.
19
     *
20
     * @return string
21
     */
22
    public function getShortName(): string
23
    {
24
        $shortName = explode('\\', get_class($this));
25
26
        return collect($shortName)->last();
27
    }
28
29
    /**
30
     * Initialize driver.
31
     *
32
     * @param array $parameters
33
     *
34
     * @return Driver|DriverContract|static
35
     */
36
    public function initialize(array $parameters): DriverContract
37
    {
38
        foreach ($this->getDefaultParameters() as $key => $value) {
39
            $value = array_get($parameters, $key, $value);
40
41
            array_set($parameters, $key, $value);
42
        }
43
44
        $this->parameters = collect($parameters);
45
46
        return $this;
47
    }
48
49
    /**
50
     * Get driver parameters.
51
     *
52
     * @return Collection
53
     */
54
    public function getParameters(): Collection
55
    {
56
        return $this->parameters;
57
    }
58
}
59