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

Config::all()   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 0
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 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
}