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

MutableConfig::merge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
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
    /**
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