Passed
Push — master ( cdf890...3fa5d8 )
by Vsevolods
03:14
created

MutableConfig::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.0156

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 4
cp 0.75
crap 1.0156
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Config;
4
5
use Venta\Contracts\Config\MutableConfig as MutableConfigContract;
6
7
/**
8
 * Class MutableConfig
9
 *
10
 * @package Venta\Config
11
 */
12
class MutableConfig extends Config implements MutableConfigContract
13
{
14
    /**
15
     * MutableConfig constructor.
16
     *
17
     * @param array $items
18
     */
19 4
    public function __construct(array $items = [])
20
    {
21 4
        parent::__construct($items);
22 4
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27 1
    public function merge(array $config)
28
    {
29 1
        $this->items = array_replace_recursive($this->items, $config);
30 1
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 1 View Code Duplication
    public function push(string $path, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37 1
        $keys = explode('.', $path);
38 1
        $array = &$this->items;
39
40 1
        while (count($keys) > 0) {
41 1
            $key = array_shift($keys);
42
43 1
            if (!isset($array[$key]) || !is_array($array[$key])) {
44 1
                $array[$key] = [];
45
            }
46
47 1
            $array = &$array[$key];
48
        }
49
50 1
        array_push($array, $value);
51 1
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56 1 View Code Duplication
    public function set(string $path, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58 1
        $keys = explode('.', $path);
59 1
        $array = &$this->items;
60
61 1
        while (count($keys) > 1) {
62 1
            $key = array_shift($keys);
63
64 1
            if (!isset($array[$key]) || !is_array($array[$key])) {
65 1
                $array[$key] = [];
66
            }
67
68 1
            $array = &$array[$key];
69
        }
70
71 1
        $array[array_shift($keys)] = $value;
72 1
    }
73
}
74