Completed
Pull Request — master (#2)
by Pedro
01:50
created

Config::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 19
ccs 6
cts 6
cp 1
rs 8.8571
cc 5
eloc 10
nc 4
nop 1
crap 5
1
<?php
2
3
namespace Pcelta\Doctrine\Cache\Entity;
4
5
use Pcelta\Doctrine\Cache\Exception\InvalidCacheConfig;
6
7
class Config
8
{
9
    /**
10
     * @var string
11
     */
12
    private $adapterName;
13
14
    /**
15
     * @var string
16
     */
17
    private $adapterNamespace = '\Doctrine\Common\Cache\%sCache';
18
19
    /**
20
     * @var array
21
     */
22
    private $settings = [];
23
24
    /**
25
     * @param array $config
26
     */
27
    public function __construct(array $config)
28
    {
29
        if (!isset($config['adapter_name']) || !is_string($config['adapter_name'])) {
30
            throw new InvalidCacheConfig('Invalid Adapter Name. Is Not A String OR Is Missing!');
31
        }
32
        $this->adapterName = $config['adapter_name'];
33
34
35
        unset($config['adapter_name']);
36
        $this->settings = $config;
37 9
38
        if (isset($config['adapter_namespace'])) {
39 9
            if (!is_string($config['adapter_namespace'])) {
40 1
                throw new InvalidCacheConfig('Invalid Adapter Namespace. Is Not A String!');
41
            }
42 8
43
            $this->adapterNamespace = $config['adapter_namespace'];
44 8
        }
45 1
    }
46
47 7
    /**
48
     * @return string
49 7
     */
50 2
    public function getAdapterName()
51
    {
52
        return $this->adapterName;
53 5
    }
54 1
55
    /**
56 4
     * @return array
57
     */
58 4
    public function getSettings()
59 1
    {
60
        return $this->settings;
61 3
    }
62
63 3
    /**
64
     * @return string
65
     */
66
    public function getAdapterNamespace()
67
    {
68
        return $this->adapterNamespace;
69
    }
70
}
71