RestrictedConfig   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 87
ccs 27
cts 27
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A getArrayCopy() 0 10 3
A getRestriction() 0 4 1
A setRestriction() 0 4 1
1
<?php
2
namespace Puppy\Config;
3
4
/**
5
 * Class RestrictedConfig
6
 * @package Puppy\Config
7
 * @author Raphaël Lefebvre <[email protected]>
8
 */
9
class RestrictedConfig extends ArrayConfig
10
{
11
    /**
12
     * @var string
13
     */
14
    private $restriction;
15
16
    /**
17
     * @param string $restriction
18
     * @param string $separator
19
     * @param array|\ArrayObject $data
20
     */
21 7
    public function __construct($restriction, $separator, $data = array())
22
    {
23 7
        $this->setRestriction($restriction . $separator);
24 7
        parent::__construct($data);
25 7
    }
26
27
    /**
28
     * @param mixed $key
29
     * @return bool
30
     */
31 3
    public function offsetExists($key)
32
    {
33 3
        return parent::offsetExists($this->getRestriction() . $key);
34
    }
35
36
    /**
37
     * @param mixed $key
38
     * @return bool
39
     */
40 3
    public function offsetGet($key)
41
    {
42 3
        return parent::offsetGet($this->getRestriction() . $key);
43
    }
44
45
    /**
46
     * @param mixed $key
47
     * @param mixed $value
48
     */
49 2
    public function offsetSet($key, $value)
50
    {
51 2
        parent::offsetSet($this->getRestriction() . $key, $value);
52 2
    }
53
54
    /**
55
     * @param mixed $key
56
     */
57 1
    public function offsetUnset($key)
58
    {
59 1
        parent::offsetUnset($this->getRestriction() . $key);
60 1
    }
61
62
    /**
63
     * @return array
64
     */
65 1
    public function getArrayCopy()
66
    {
67 1
        $result = [];
68 1
        foreach(parent::getArrayCopy() as $key => $value){
69 1
            if(strpos($key, $this->getRestriction()) === 0){
70 1
                $result[str_replace($this->getRestriction(), '', $key)] = $value;
71 1
            }
72 1
        }
73 1
        return $result;
74
    }
75
76
    /**
77
     * Getter of $restriction
78
     *
79
     * @return string
80
     */
81 7
    private function getRestriction()
82
    {
83 7
        return $this->restriction;
84
    }
85
86
    /**
87
     * Setter of $restriction
88
     *
89
     * @param string $restriction
90
     */
91 7
    private function setRestriction($restriction)
92
    {
93 7
        $this->restriction = (string)$restriction;
94 7
    }
95
}
96