AbstractStorageFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 3
eloc 12
c 2
b 0
f 2
dl 0
loc 56
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A returnStorageObject() 0 12 2
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\Storage;
13
14
use InvalidArgumentException;
15
16
/**
17
 * Storage Factory.
18
 */
19
abstract class AbstractStorageFactory
20
{
21
    /**
22
     * @var string One of supported drivers
23
     */
24
    protected string $driver = '';
25
26
    /**
27
     * @var array<string> Factory supported driver
28
     */
29
    protected array $supportedDriver = [];
30
31
    /**
32
     * @var array<mixed> Options for the driver
33
     */
34
    protected array $options = [];
35
36
    /**
37
     * Constructor.
38
     *
39
     * @param string       $driver
40
     * @param array<mixed> $options
41
     */
42 22
    public function __construct(string $driver, array $options)
43
    {
44 22
        $this->driver = $driver;
45 22
        $this->options = $options;
46 22
    }
47
48
    /**
49
     * Return Storage Object.
50
     *
51
     * @throws InvalidArgumentException If required driver is not supported
52
     *
53
     * @return mixed
54
     */
55 22
    protected function returnStorageObject()
56
    {
57 22
        $driver = $this->driver;
58 22
        $options = $this->options;
59
60 22
        if (isset($this->supportedDriver[$driver])) {
61 20
            $class = $this->supportedDriver[$driver];
62
63 20
            return new $class($options);
64
        }
65
66 2
        throw new InvalidArgumentException("[{$driver}] not supported.");
67
    }
68
69
    /**
70
     * Get storage object.
71
     *
72
     * @return mixed
73
     */
74
    abstract public function get();
75
}
76