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

MutableConfig   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 54.84 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
dl 34
loc 62
ccs 26
cts 34
cp 0.7647
rs 10
c 0
b 0
f 0
wmc 10
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A merge() 0 4 1
A push() 17 17 4
A set() 17 17 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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