Completed
Push — master ( e15c58...b150a8 )
by Changwan
07:08
created

Config::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Config;
3
4
use Wandu\Config\Contracts\ConfigInterface;
5
use Wandu\Config\Exception\NotAllowedMethodException;
6
use Wandu\Support\DotArray;
7
8
class Config extends DotArray implements ConfigInterface
9
{
10
    /** @var bool */
11
    protected $readOnly;
12
13
    /**
14
     * @param array $items
15
     * @param bool $readOnly
16
     */
17 17
    public function __construct(array $items = [], $readOnly = true)
18
    {
19 17
        parent::__construct($items);
20 17
        $this->readOnly = $readOnly;
21 17
    }
22
    
23
    /**
24
     * {@inheritdoc}
25
     */
26 3
    public function set($name, $value)
27
    {
28 3
        if ($this->readOnly) {
29 2
            throw new NotAllowedMethodException(__FUNCTION__, __CLASS__);
30
        }
31 1
        return parent::set($name, $value);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 2
    public function remove($name)
38
    {
39 2
        if ($this->readOnly) {
40 1
            throw new NotAllowedMethodException(__FUNCTION__, __CLASS__);
41
        }
42 1
        return parent::remove($name);
43
    }
44
}
45