Service   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 77.27%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 44
ccs 17
cts 22
cp 0.7727
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A cacheSet() 0 13 2
B get() 0 19 5
1
<?php
2
/**
3
 * Opine\Config\Service
4
 *
5
 * Copyright (c)2013, 2014 Ryan Mahoney, https://github.com/Opine-Org <[email protected]>
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
namespace Opine\Config;
26
27
use Opine\Cache\Service as Cache;
28
use Opine\Interfaces\Config as ConfigInterface;
29
30
class Service implements ConfigInterface
31
{
32
    private $cache = false;
33
    private $root;
34
35 3
    public function __construct($root)
36
    {
37 3
        $this->root = $root;
38 3
    }
39
40 3
    public function cacheSet(Array $config = [])
41
    {
42 3
        if (empty($config)) {
43 3
            $model = new Model($this->root, new Cache($this->root));
44 3
            $model->build();
45 3
            $this->cache = $model->getCacheFileData();
46
47 3
            return true;
48
        }
49
        $this->cache = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config of type array is incompatible with the declared type boolean of property $cache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
51
        return true;
52
    }
53
54 3
    public function get($key)
55
    {
56 3
        if (substr_count($key, '.') == 1) {
57 1
            $parts = explode('.', $key);
58 1
            if (!isset($this->cache[$parts[0]])) {
59
                return null;
60
            }
61 1
            if (!isset($this->cache[$parts[0]][$parts[1]])) {
62
                return null;
63
            }
64 1
            return $this->cache[$parts[0]][$parts[1]];
65
        }
66
67 2
        if (!isset($this->cache[$key])) {
68
            return null;
69
        }
70
71 2
        return $this->cache[$key];
72
    }
73
}
74