StorageManager::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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
}