Passed
Push — master ( 72194f...754eba )
by Alexey
05:19
created

MutableConfig::set()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 3
nop 2
dl 17
loc 17
ccs 0
cts 13
cp 0
crap 20
rs 9.2
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
    /**
16
     * @inheritdoc
17
     */
18
    public function merge(array $config)
19
    {
20
        $this->items = array_merge_recursive($this->items, $config);
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26 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...
27
    {
28
        $keys = explode('.', $path);
29
        $array = &$this->items;
30
31
        while (count($keys) > 0) {
32
            $activeKey = array_shift($keys);
33
34
            if (!isset($array[$activeKey]) || !is_array($array[$activeKey])) {
35
                $array[$activeKey] = [$array[$activeKey]];
36
            }
37
38
            $array = &$array[$activeKey];
39
        }
40
41
        array_push($array, $value);
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 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...
48
    {
49
        $keys = explode('.', $path);
50
        $array = &$this->items;
51
52
        while (count($keys) > 1) {
53
            $activeKey = array_shift($keys);
54
55
            if (!isset($array[$activeKey]) || !is_array($array[$activeKey])) {
56
                $array[$activeKey] = [];
57
            }
58
59
            $array = &$array[$activeKey];
60
        }
61
62
        $array[array_shift($keys)] = $value;
63
    }
64
}
65