StorageManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdapter() 0 9 3
A __construct() 0 6 2
1
<?php
2
3
namespace devtoolboxuk\storage;
4
5
use devtoolboxuk\storage\Adapter\AdapterFactory;
6
7
class StorageManager
8
{
9
    protected $adapter;
10
    protected $adapterName;
11
12
    function __construct($options = [])
13
    {
14
        if (isset($options['adapter'])) {
15
            $this->adapterName = $options['adapter'];
16
            $factory = AdapterFactory::instance();
17
            $this->adapter = $factory->getAdapter($options['adapter'], $options);
18
        }
19
    }
20
21
    public function getAdapter()
22
    {
23
        if (isset($this->adapter)) {
24
            return $this->adapter;
25
        } else {
26
            if ($this->adapterName) {
27
                throw new \RuntimeException(sprintf('The specified adapter "%s" is not configured', $this->adapterName));
28
            } else {
29
                throw new \RuntimeException('No adapter has been specified');
30
            }
31
        }
32
33
    }
34
35
}