Test Failed
Push — master ( e5208b...d1bce3 )
by Alain
02:38
created
src/AbstractConfig.php 1 patch
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -28,225 +28,225 @@
 block discarded – undo
28 28
 abstract class AbstractConfig extends ArrayObject implements ConfigInterface
29 29
 {
30 30
 
31
-    /**
32
-     * Array of strings that are used as delimiters to parse configuration keys.
33
-     *
34
-     * @since 0.1.6
35
-     *
36
-     * @var array
37
-     */
38
-    protected $delimiter = ['\\', '/', '.'];
39
-
40
-    /**
41
-     * Instantiate the AbstractConfig object.
42
-     *
43
-     * @since 0.1.0
44
-     * @since 0.1.6 Accepts a delimiter to parse configuration keys.
45
-     *
46
-     * @param array                $config    Array with settings.
47
-     * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse
48
-     *                                        configuration keys. Defaults to "\", "/" & ".".
49
-     */
50
-    public function __construct(array $config, $delimiter = null)
51
-    {
52
-        // Make sure the config entries can be accessed as properties.
53
-        parent::__construct($config, ArrayObject::ARRAY_AS_PROPS);
54
-
55
-        if (null !== $delimiter) {
56
-            $this->delimiter = (array)$delimiter;
57
-        }
58
-    }
59
-
60
-    /**
61
-     * Get the value of a specific key.
62
-     *
63
-     * To get a value several levels deep, add the keys for each level as a comma-separated list.
64
-     *
65
-     * @since 0.1.0
66
-     * @since 0.1.4 Accepts list of keys.
67
-     *
68
-     * @param string $_ List of keys.
69
-     * @return mixed
70
-     * @throws BadMethodCallException If no argument was provided.
71
-     * @throws OutOfRangeException If an unknown key is requested.
72
-     */
73
-    public function getKey($_)
74
-    {
75
-        $keys = $this->validateKeys(func_get_args());
76
-
77
-        $keys  = array_reverse($keys);
78
-        $array = $this->getArrayCopy();
79
-        while (count($keys) > 0) {
80
-            $key   = array_pop($keys);
81
-            $array = $array[$key];
82
-        }
83
-
84
-        return $array;
85
-    }
86
-
87
-    /**
88
-     * Check whether the Config has a specific key.
89
-     *
90
-     * To check a value several levels deep, add the keys for each level as a comma-separated list.
91
-     *
92
-     * @since 0.1.0
93
-     * @since 0.1.4 Accepts list of keys.
94
-     *
95
-     * @param string $_ List of keys.
96
-     * @return bool
97
-     */
98
-    public function hasKey($_)
99
-    {
100
-        try {
101
-            $keys = array_reverse($this->getKeyArguments(func_get_args()));
102
-
103
-            $array = $this->getArrayCopy();
104
-            while (count($keys) > 0) {
105
-                $key = array_pop($keys);
106
-                if (! array_key_exists($key, $array)) {
107
-                    return false;
108
-                }
109
-                $array = $array[$key];
110
-            }
111
-        } catch (Exception $exception) {
112
-            return false;
113
-        }
114
-
115
-        return true;
116
-    }
117
-
118
-    /**
119
-     * Get a (multi-dimensional) array of all the configuration settings.
120
-     *
121
-     * @since 0.1.4
122
-     *
123
-     * @return array
124
-     */
125
-    public function getAll()
126
-    {
127
-        return $this->getArrayCopy();
128
-    }
129
-
130
-    /**
131
-     * Get the an array with all the keys
132
-     *
133
-     * @since 0.1.0
134
-     * @return array
135
-     */
136
-    public function getKeys()
137
-    {
138
-        return array_keys((array)$this);
139
-    }
140
-
141
-    /**
142
-     * Get a new config at a specific sub-level.
143
-     *
144
-     * @since 0.1.13
145
-     *
146
-     * @param string $_ List of keys.
147
-     * @return ConfigInterface
148
-     * @throws BadMethodCallException If no argument was provided.
149
-     * @throws OutOfRangeException If an unknown key is requested.
150
-     */
151
-    public function getSubConfig($_)
152
-    {
153
-        $keys = $this->validateKeys(func_get_args());
154
-
155
-        $subConfig = clone $this;
156
-        $subConfig->reduceToSubKey($keys);
157
-
158
-        return $subConfig;
159
-    }
160
-
161
-    /**
162
-     * Validate a set of keys to make sure they exist.
163
-     *
164
-     * @since 0.1.13
165
-     *
166
-     * @param string $_ List of keys.
167
-     * @return array List of keys.
168
-     * @throws BadMethodCallException If no argument was provided.
169
-     * @throws OutOfRangeException If an unknown key is requested.
170
-     */
171
-    public function validateKeys($_)
172
-    {
173
-        $keys = $this->getKeyArguments(func_get_args());
174
-
175
-        Assert\that($keys)->all()->string()->notEmpty();
176
-
177
-        if (! $this->hasKey($keys)) {
178
-            throw new OutOfRangeException(
179
-                sprintf(
180
-                    _('The configuration key %1$s does not exist.'),
181
-                    implode('->', $keys)
182
-                )
183
-            );
184
-        }
185
-
186
-        return $keys;
187
-    }
188
-
189
-    /**
190
-     * Reduce the currently stored config array to a subarray at a specific level.
191
-     *
192
-     * @since 0.1.13
193
-     *
194
-     * @param array $keys Array of keys that point to a key down in the hierarchy.
195
-     */
196
-    protected function reduceToSubKey(array $keys)
197
-    {
198
-        $this->exchangeArray($this->getKey($keys));
199
-    }
200
-
201
-    /**
202
-     * Recursively extract the configuration key arguments from an arbitrary array.
203
-     *
204
-     * @since 0.1.6
205
-     *
206
-     * @param array $arguments Array as fetched through get_func_args().
207
-     * @return array Array of strings.
208
-     * @throws BadMethodCallException If no argument was provided.
209
-     */
210
-    protected function getKeyArguments($arguments)
211
-    {
212
-        Assert\that($arguments)->isArray()->notEmpty();
213
-
214
-        $keys = [];
215
-        foreach ($arguments as $argument) {
216
-            if (is_array($argument)) {
217
-                $keys = array_merge($keys, $this->getKeyArguments($argument));
218
-            }
219
-            if (is_string($argument)) {
220
-                $keys = array_merge($keys, $this->parseKeysString($argument));
221
-            }
222
-        }
223
-
224
-        return $keys;
225
-    }
226
-
227
-    /**
228
-     * Extract individual keys from a delimited string.
229
-     *
230
-     * @since 0.1.6
231
-     *
232
-     * @param string $keyString Delimited string of keys.
233
-     * @return array Array of key strings.
234
-     */
235
-    protected function parseKeysString($keyString)
236
-    {
237
-        Assert\that($keyString)->string()->notEmpty();
238
-
239
-        // Replace all of the configured delimiters by the first one, so that we can then use explode().
240
-        $normalizedString = str_replace($this->delimiter, $this->delimiter[0], $keyString);
241
-
242
-        return (array)explode($this->delimiter[0], $normalizedString);
243
-    }
244
-
245
-    /**
246
-     * Validate the Config file.
247
-     *
248
-     * @since  0.1.0
249
-     * @return boolean
250
-     */
251
-    abstract public function isValid();
31
+	/**
32
+	 * Array of strings that are used as delimiters to parse configuration keys.
33
+	 *
34
+	 * @since 0.1.6
35
+	 *
36
+	 * @var array
37
+	 */
38
+	protected $delimiter = ['\\', '/', '.'];
39
+
40
+	/**
41
+	 * Instantiate the AbstractConfig object.
42
+	 *
43
+	 * @since 0.1.0
44
+	 * @since 0.1.6 Accepts a delimiter to parse configuration keys.
45
+	 *
46
+	 * @param array                $config    Array with settings.
47
+	 * @param string[]|string|null $delimiter A string or array of strings that are used as delimiters to parse
48
+	 *                                        configuration keys. Defaults to "\", "/" & ".".
49
+	 */
50
+	public function __construct(array $config, $delimiter = null)
51
+	{
52
+		// Make sure the config entries can be accessed as properties.
53
+		parent::__construct($config, ArrayObject::ARRAY_AS_PROPS);
54
+
55
+		if (null !== $delimiter) {
56
+			$this->delimiter = (array)$delimiter;
57
+		}
58
+	}
59
+
60
+	/**
61
+	 * Get the value of a specific key.
62
+	 *
63
+	 * To get a value several levels deep, add the keys for each level as a comma-separated list.
64
+	 *
65
+	 * @since 0.1.0
66
+	 * @since 0.1.4 Accepts list of keys.
67
+	 *
68
+	 * @param string $_ List of keys.
69
+	 * @return mixed
70
+	 * @throws BadMethodCallException If no argument was provided.
71
+	 * @throws OutOfRangeException If an unknown key is requested.
72
+	 */
73
+	public function getKey($_)
74
+	{
75
+		$keys = $this->validateKeys(func_get_args());
76
+
77
+		$keys  = array_reverse($keys);
78
+		$array = $this->getArrayCopy();
79
+		while (count($keys) > 0) {
80
+			$key   = array_pop($keys);
81
+			$array = $array[$key];
82
+		}
83
+
84
+		return $array;
85
+	}
86
+
87
+	/**
88
+	 * Check whether the Config has a specific key.
89
+	 *
90
+	 * To check a value several levels deep, add the keys for each level as a comma-separated list.
91
+	 *
92
+	 * @since 0.1.0
93
+	 * @since 0.1.4 Accepts list of keys.
94
+	 *
95
+	 * @param string $_ List of keys.
96
+	 * @return bool
97
+	 */
98
+	public function hasKey($_)
99
+	{
100
+		try {
101
+			$keys = array_reverse($this->getKeyArguments(func_get_args()));
102
+
103
+			$array = $this->getArrayCopy();
104
+			while (count($keys) > 0) {
105
+				$key = array_pop($keys);
106
+				if (! array_key_exists($key, $array)) {
107
+					return false;
108
+				}
109
+				$array = $array[$key];
110
+			}
111
+		} catch (Exception $exception) {
112
+			return false;
113
+		}
114
+
115
+		return true;
116
+	}
117
+
118
+	/**
119
+	 * Get a (multi-dimensional) array of all the configuration settings.
120
+	 *
121
+	 * @since 0.1.4
122
+	 *
123
+	 * @return array
124
+	 */
125
+	public function getAll()
126
+	{
127
+		return $this->getArrayCopy();
128
+	}
129
+
130
+	/**
131
+	 * Get the an array with all the keys
132
+	 *
133
+	 * @since 0.1.0
134
+	 * @return array
135
+	 */
136
+	public function getKeys()
137
+	{
138
+		return array_keys((array)$this);
139
+	}
140
+
141
+	/**
142
+	 * Get a new config at a specific sub-level.
143
+	 *
144
+	 * @since 0.1.13
145
+	 *
146
+	 * @param string $_ List of keys.
147
+	 * @return ConfigInterface
148
+	 * @throws BadMethodCallException If no argument was provided.
149
+	 * @throws OutOfRangeException If an unknown key is requested.
150
+	 */
151
+	public function getSubConfig($_)
152
+	{
153
+		$keys = $this->validateKeys(func_get_args());
154
+
155
+		$subConfig = clone $this;
156
+		$subConfig->reduceToSubKey($keys);
157
+
158
+		return $subConfig;
159
+	}
160
+
161
+	/**
162
+	 * Validate a set of keys to make sure they exist.
163
+	 *
164
+	 * @since 0.1.13
165
+	 *
166
+	 * @param string $_ List of keys.
167
+	 * @return array List of keys.
168
+	 * @throws BadMethodCallException If no argument was provided.
169
+	 * @throws OutOfRangeException If an unknown key is requested.
170
+	 */
171
+	public function validateKeys($_)
172
+	{
173
+		$keys = $this->getKeyArguments(func_get_args());
174
+
175
+		Assert\that($keys)->all()->string()->notEmpty();
176
+
177
+		if (! $this->hasKey($keys)) {
178
+			throw new OutOfRangeException(
179
+				sprintf(
180
+					_('The configuration key %1$s does not exist.'),
181
+					implode('->', $keys)
182
+				)
183
+			);
184
+		}
185
+
186
+		return $keys;
187
+	}
188
+
189
+	/**
190
+	 * Reduce the currently stored config array to a subarray at a specific level.
191
+	 *
192
+	 * @since 0.1.13
193
+	 *
194
+	 * @param array $keys Array of keys that point to a key down in the hierarchy.
195
+	 */
196
+	protected function reduceToSubKey(array $keys)
197
+	{
198
+		$this->exchangeArray($this->getKey($keys));
199
+	}
200
+
201
+	/**
202
+	 * Recursively extract the configuration key arguments from an arbitrary array.
203
+	 *
204
+	 * @since 0.1.6
205
+	 *
206
+	 * @param array $arguments Array as fetched through get_func_args().
207
+	 * @return array Array of strings.
208
+	 * @throws BadMethodCallException If no argument was provided.
209
+	 */
210
+	protected function getKeyArguments($arguments)
211
+	{
212
+		Assert\that($arguments)->isArray()->notEmpty();
213
+
214
+		$keys = [];
215
+		foreach ($arguments as $argument) {
216
+			if (is_array($argument)) {
217
+				$keys = array_merge($keys, $this->getKeyArguments($argument));
218
+			}
219
+			if (is_string($argument)) {
220
+				$keys = array_merge($keys, $this->parseKeysString($argument));
221
+			}
222
+		}
223
+
224
+		return $keys;
225
+	}
226
+
227
+	/**
228
+	 * Extract individual keys from a delimited string.
229
+	 *
230
+	 * @since 0.1.6
231
+	 *
232
+	 * @param string $keyString Delimited string of keys.
233
+	 * @return array Array of key strings.
234
+	 */
235
+	protected function parseKeysString($keyString)
236
+	{
237
+		Assert\that($keyString)->string()->notEmpty();
238
+
239
+		// Replace all of the configured delimiters by the first one, so that we can then use explode().
240
+		$normalizedString = str_replace($this->delimiter, $this->delimiter[0], $keyString);
241
+
242
+		return (array)explode($this->delimiter[0], $normalizedString);
243
+	}
244
+
245
+	/**
246
+	 * Validate the Config file.
247
+	 *
248
+	 * @since  0.1.0
249
+	 * @return boolean
250
+	 */
251
+	abstract public function isValid();
252 252
 }
Please login to merge, or discard this patch.
src/ConfigInterface.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Config Interface
4
- *
5
- * @package   BrightNucleus\Config
6
- * @author    Alain Schlesser <[email protected]>
7
- * @license   GPL-2.0+
8
- * @link      http://www.brightnucleus.com/
9
- * @copyright 2016 Alain Schlesser, Bright Nucleus
10
- */
3
+	 * Config Interface
4
+	 *
5
+	 * @package   BrightNucleus\Config
6
+	 * @author    Alain Schlesser <[email protected]>
7
+	 * @license   GPL-2.0+
8
+	 * @link      http://www.brightnucleus.com/
9
+	 * @copyright 2016 Alain Schlesser, Bright Nucleus
10
+	 */
11 11
 
12 12
 namespace BrightNucleus\Config;
13 13
 
@@ -27,79 +27,79 @@  discard block
 block discarded – undo
27 27
 interface ConfigInterface extends IteratorAggregate, ArrayAccess, Serializable, Countable
28 28
 {
29 29
 
30
-    /**
31
-     * Creates a copy of the ArrayObject.
32
-     *
33
-     * Returns a copy of the array. When the ArrayObject refers to an object an
34
-     * array of the public properties of that object will be returned.
35
-     * This is implemented by \ArrayObject.
36
-     *
37
-     * @since 0.1.0
38
-     *
39
-     * @return array Copy of the array.
40
-     */
41
-    public function getArrayCopy();
30
+	/**
31
+	 * Creates a copy of the ArrayObject.
32
+	 *
33
+	 * Returns a copy of the array. When the ArrayObject refers to an object an
34
+	 * array of the public properties of that object will be returned.
35
+	 * This is implemented by \ArrayObject.
36
+	 *
37
+	 * @since 0.1.0
38
+	 *
39
+	 * @return array Copy of the array.
40
+	 */
41
+	public function getArrayCopy();
42 42
 
43
-    /**
44
-     * Check whether the Config has a specific key.
45
-     *
46
-     * To check a value several levels deep, add the keys for each level as a comma-separated list.
47
-     *
48
-     * @since 0.1.0
49
-     * @since 0.1.4 Accepts list of keys.
50
-     *
51
-     * @param string $_ List of keys.
52
-     * @return bool
53
-     */
54
-    public function hasKey($_);
43
+	/**
44
+	 * Check whether the Config has a specific key.
45
+	 *
46
+	 * To check a value several levels deep, add the keys for each level as a comma-separated list.
47
+	 *
48
+	 * @since 0.1.0
49
+	 * @since 0.1.4 Accepts list of keys.
50
+	 *
51
+	 * @param string $_ List of keys.
52
+	 * @return bool
53
+	 */
54
+	public function hasKey($_);
55 55
 
56
-    /**
57
-     * Get the value of a specific key.
58
-     *
59
-     * To get a value several levels deep, add the keys for each level as a comma-separated list.
60
-     *
61
-     * @since 0.1.0
62
-     * @since 0.1.4 Accepts list of keys.
63
-     *
64
-     * @param string $_ List of keys.
65
-     * @return mixed
66
-     */
67
-    public function getKey($_);
56
+	/**
57
+	 * Get the value of a specific key.
58
+	 *
59
+	 * To get a value several levels deep, add the keys for each level as a comma-separated list.
60
+	 *
61
+	 * @since 0.1.0
62
+	 * @since 0.1.4 Accepts list of keys.
63
+	 *
64
+	 * @param string $_ List of keys.
65
+	 * @return mixed
66
+	 */
67
+	public function getKey($_);
68 68
 
69
-    /**
70
-     * Get a (multi-dimensional) array of all the configuration settings.
71
-     *
72
-     * @since 0.1.4
73
-     *
74
-     * @return array
75
-     */
76
-    public function getAll();
69
+	/**
70
+	 * Get a (multi-dimensional) array of all the configuration settings.
71
+	 *
72
+	 * @since 0.1.4
73
+	 *
74
+	 * @return array
75
+	 */
76
+	public function getAll();
77 77
 
78
-    /**
79
-     * Get the an array with all the keys
80
-     *
81
-     * @since 0.1.0
82
-     *
83
-     * @return mixed
84
-     */
85
-    public function getKeys();
78
+	/**
79
+	 * Get the an array with all the keys
80
+	 *
81
+	 * @since 0.1.0
82
+	 *
83
+	 * @return mixed
84
+	 */
85
+	public function getKeys();
86 86
 
87
-    /**
88
-     * Is the Config valid?
89
-     *
90
-     * @since 0.1.0
91
-     *
92
-     * @return boolean
93
-     */
94
-    public function isValid();
87
+	/**
88
+	 * Is the Config valid?
89
+	 *
90
+	 * @since 0.1.0
91
+	 *
92
+	 * @return boolean
93
+	 */
94
+	public function isValid();
95 95
 
96
-    /**
97
-     * Get a new config at a specific sub-level.
98
-     *
99
-     * @since 0.1.13
100
-     *
101
-     * @param string $_ List of keys.
102
-     * @return ConfigInterface
103
-     */
104
-    public function getSubConfig($_);
96
+	/**
97
+	 * Get a new config at a specific sub-level.
98
+	 *
99
+	 * @since 0.1.13
100
+	 *
101
+	 * @param string $_ List of keys.
102
+	 * @return ConfigInterface
103
+	 */
104
+	public function getSubConfig($_);
105 105
 }
Please login to merge, or discard this patch.