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

Config   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 89
Duplicated Lines 33.71 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 54.35%

Importance

Changes 0
Metric Value
dl 30
loc 89
ccs 25
cts 46
cp 0.5435
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 0 4 1
A count() 0 4 1
A get() 15 15 3
A getIterator() 0 4 1
A has() 15 15 3
A jsonSerialize() 0 4 1

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 ArrayIterator;
6
use IteratorAggregate;
7
use Venta\Contracts\Config\Config as ConfigContract;
8
9
/**
10
 * Class Config
11
 *
12
 * @package Venta\Config
13
 */
14
class Config implements IteratorAggregate, ConfigContract
15
{
16
    /**
17
     * Array of configuration items.
18
     *
19
     * @var array
20
     */
21
    protected $items = [];
22
23
    /**
24
     * Construct function.
25
     *
26
     * @param array $items
27
     */
28 6
    public function __construct(array $items)
29
    {
30 6
        $this->items = $items;
31 6
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function all(): array
37
    {
38
        return $this->items;
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44 1
    public function count()
45
    {
46 1
        return count($this->items);
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52 1 View Code Duplication
    public function get(string $key, $default = null)
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...
53
    {
54 1
        $keys = explode('.', $key);
55 1
        $items = $this->items;
56
57 1
        foreach ($keys as $key) {
58 1
            if (array_key_exists($key, $items)) {
59 1
                $items = $items[$key];
60
            } else {
61 1
                return $default;
62
            }
63
        }
64
65 1
        return $items;
66
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71 1
    public function getIterator()
72
    {
73 1
        return new ArrayIterator($this->items);
74
    }
75
76
    /**
77
     * @inheritDoc
78
     */
79 1 View Code Duplication
    public function has(string $key): bool
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...
80
    {
81 1
        $keys = explode('.', $key);
82 1
        $items = $this->items;
83
84 1
        foreach ($keys as $key) {
85 1
            if (array_key_exists($key, $items)) {
86 1
                $items = $items[$key];
87
            } else {
88 1
                return false;
89
            }
90
        }
91
92 1
        return true;
93
    }
94
95
    /**
96
     * @inheritDoc
97
     */
98 1
    public function jsonSerialize()
99
    {
100 1
        return $this->items;
101
    }
102
}