Collection   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 142
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 4

12 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 5 1
A set() 0 9 2
A remove() 0 4 1
A get() 0 18 4
A reset() 0 5 1
A __get() 0 4 1
A __call() 0 4 1
A __isset() 0 4 1
A offsetExists() 0 5 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Sinergi\Config;
4
5
require_once __DIR__ . "/DotenvHelper.php";
6
7
use InvalidArgumentException;
8
use ArrayAccess;
9
10
class Collection extends Configuration implements ArrayAccess
11
{
12
    /**
13
     * @param array|Configuration $config
14
     * @return Collection
15
     */
16
    public static function factory($config)
17
    {
18
        $factory = new Factory();
19
        return $factory($config);
20
    }
21
22
    /**
23
     * @var array
24
     */
25
    private $container = [];
26
27
    /**
28
     * Set a config
29
     *
30
     * @param string $name
31
     * @param array $config
32
     * @return $this
33
     */
34
    public function set($name, $config)
35
    {
36
        if (!isset($this->container[$name])) {
37
            $this->container[$name] = $config;
38
        } else {
39
            $this->container[$name] = array_merge($this->container[$name], $config);
40
        }
41
        return $this;
42
    }
43
44
    /**
45
     * @param string $name
46
     */
47
    public function remove($name)
48
    {
49
        unset($this->container[$name]);
50
    }
51
52
    /**
53
     * Get a config
54
     *
55
     * @param string $name
56
     * @param mixed $default
57
     * @throws InvalidArgumentException
58
     * @return mixed
59
     */
60
    public function get($name, $default = null)
61
    {
62
        if (!is_string($name) || empty($name)) {
63
            throw new InvalidArgumentException("Parameter \$name passed to Config::get() is not a valid string resource");
64
        }
65
66
        list($file, $key, $sub) = Parser::getKey($name);
67
68
        if (!isset($this->container[$file])) {
69
            $this->container[$file] = Loader::load(
70
                $this->paths,
71
                $this->environment,
72
                $file
73
            );
74
        }
75
76
        return Parser::getValue($this->container[$file], $key, $sub, $default);
77
    }
78
79
    /**
80
     * @return $this
81
     */
82
    public function reset()
83
    {
84
        $this->container = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $container.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
85
        return $this;
86
    }
87
88
    /**
89
     * @param string $name
90
     * @return mixed
91
     */
92
    public function __get($name)
93
    {
94
        return $this->offsetGet($name);
95
    }
96
97
    /**
98
     * @param string $name
99
     * @param array|null $args
100
     * @return mixed
101
     */
102
    public function __call($name, $args = null)
103
    {
104
        return $this->offsetGet($name);
105
    }
106
107
    /**
108
     * @param string $name
109
     * @return bool
110
     */
111
    public function __isset($name)
112
    {
113
        return $this->offsetExists($name);
114
    }
115
116
    /**
117
     * @param int $offset
118
     * @return bool
119
     */
120
    public function offsetExists($offset)
121
    {
122
        $item = $this->get($offset);
123
        return isset($item);
124
    }
125
126
    /**
127
     * @param int $offset
128
     * @return mixed
129
     */
130
    public function offsetGet($offset)
131
    {
132
        return $this->get($offset);
133
    }
134
135
    /**
136
     * @param int $offset
137
     * @param mixed $value
138
     */
139
    public function offsetSet($offset, $value)
140
    {
141
        $this->set($offset, $value);
142
    }
143
144
    /**
145
     * @param int $offset
146
     */
147
    public function offsetUnset($offset)
148
    {
149
        $this->remove($offset);
150
    }
151
}
152