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

MutableConfig::push()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 4.1967

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 3
nop 2
dl 17
loc 17
ccs 10
cts 13
cp 0.7692
crap 4.1967
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
     * 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