Test Failed
Push — master ( 978050...cc6d64 )
by Konstantins
03:20
created

Config::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Config;
4
5
use ArrayIterator;
6
use RuntimeException;
7
use Traversable;
8
use Venta\Contracts\Config\Config as ConfigContract;
9
use Venta\Routing\ProcessingRouteCollection;
10
11
/**
12
 * Class Config
13
 *
14
 * @package Venta\Config
15
 */
16
final class Config implements ConfigContract
17
{
18
    /**
19
     * Array of configuration items.
20
     *
21
     * @var array
22
     */
23
    private $items = [];
24
25
    /**
26
     * Construct function.
27
     *
28
     * @param array $items
29
     */
30 8
    public function __construct(array $items)
31
    {
32 8
        $this->items = $items;
33 8
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38 1
    public function count()
39
    {
40 1
        return count($this->items);
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 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...
47
    {
48 1
        $keys = explode('.', $key);
49 1
        $items = $this->items;
50
51 1
        foreach ($keys as $key) {
52 1
            if (array_key_exists($key, $items)) {
53 1
                $items = $items[$key];
54
            } else {
55 1
                return $default;
56
            }
57
        }
58
59 1
        return $items;
60
    }
61
62
    /**
63
     * @inheritDoc
64
     */
65 1
    public function getIterator()
66
    {
67 1
        return new ArrayIterator($this->items);
68
    }
69
70
    /**
71
     * @inheritDoc
72
     */
73 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...
74
    {
75 1
        $keys = explode('.', $key);
76 1
        $items = $this->items;
77
78 1
        foreach ($keys as $key) {
79 1
            if (array_key_exists($key, $items)) {
80 1
                $items = $items[$key];
81
            } else {
82 1
                return false;
83
            }
84
        }
85
86 1
        return true;
87
    }
88
89
    /**
90
     * @inheritDoc
91
     */
92 1
    public function jsonSerialize()
93
    {
94 1
        return $this->items;
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100 2
    public function toArray(): array
101
    {
102 2
        return $this->items;
103
    }
104
}