@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | public function setSource(&$source): void |
50 | 50 | { |
51 | 51 | /** @var array<scalar, mixed>|object|mixed|null $source */ |
52 | - if($source === null) { |
|
52 | + if ($source === null) { |
|
53 | 53 | $source = []; |
54 | 54 | } |
55 | 55 | |
56 | - if(is_scalar($source)) { |
|
56 | + if (is_scalar($source)) { |
|
57 | 57 | throw NestedAccessorException::createAsSourceIsScalar($source); |
58 | 58 | } |
59 | 59 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function get($path = null, bool $strict = true) |
68 | 68 | { |
69 | 69 | // when path is not specified |
70 | - if($path === null || $path === '') { |
|
70 | + if ($path === null || $path === '') { |
|
71 | 71 | // let's return the full source |
72 | 72 | return $this->source; |
73 | 73 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | ); |
88 | 88 | |
89 | 89 | // when strict mode is on and we got errors |
90 | - if($strict && $errorsCount) { |
|
90 | + if ($strict && $errorsCount) { |
|
91 | 91 | throw NestedAccessorException::createAsCannotGetValue( |
92 | 92 | implode($this->pathDelimiter, $path), |
93 | 93 | $errorsCount |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | { |
123 | 123 | $path = $this->formatPath($path); |
124 | 124 | |
125 | - if(!$this->exist($path)) { |
|
126 | - if($strict) { |
|
125 | + if (!$this->exist($path)) { |
|
126 | + if ($strict) { |
|
127 | 127 | throw NestedAccessorException::createAsCannotSetValue( |
128 | 128 | self::SET_MODE_DELETE, |
129 | 129 | implode($this->pathDelimiter, $path) |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | try { |
144 | 144 | $this->get($path); |
145 | 145 | return true; |
146 | - } catch(NestedAccessorException $e) { |
|
146 | + } catch (NestedAccessorException $e) { |
|
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | { |
156 | 156 | try { |
157 | 157 | return $this->get($path) !== null; |
158 | - } catch(NestedAccessorException $e) { |
|
158 | + } catch (NestedAccessorException $e) { |
|
159 | 159 | return false; |
160 | 160 | } |
161 | 161 | } |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | protected function _get($source, array $path, &$result, int &$errorsCount): void |
172 | 172 | { |
173 | 173 | // let's iterate every path part from stack |
174 | - while(count($path)) { |
|
175 | - if(is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
174 | + while (count($path)) { |
|
175 | + if (is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
176 | 176 | // the result will be multiple |
177 | - if(!is_array($result)) { |
|
177 | + if (!is_array($result)) { |
|
178 | 178 | $result = []; |
179 | 179 | } |
180 | 180 | // and we need to use recursive call for each item of this array |
181 | - foreach($source as $item) { |
|
181 | + foreach ($source as $item) { |
|
182 | 182 | $this->_get($item, $path, $result, $errorsCount); |
183 | 183 | } |
184 | 184 | // we don't need to do something in this recursive branch |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | $key = array_pop($path); |
189 | 189 | |
190 | - if(MapAccessor::exists($source, $key)) { |
|
190 | + if (MapAccessor::exists($source, $key)) { |
|
191 | 191 | // go to the next nested level |
192 | 192 | $source = MapAccessor::get($source, $key); |
193 | 193 | } else { |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | // when it's not the last iteration of the stack |
201 | 201 | // and the source is non-associative array (list) |
202 | 202 | /** @var mixed $source */ |
203 | - if(count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
203 | + if (count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
204 | 204 | // the result will be multiple |
205 | - if(!is_array($result)) { |
|
205 | + if (!is_array($result)) { |
|
206 | 206 | $result = []; |
207 | 207 | } |
208 | 208 | // and we need to use recursive call for each item of this array |
209 | - foreach($source as $item) { |
|
209 | + foreach ($source as $item) { |
|
210 | 210 | $this->_get($item, $path, $result, $errorsCount); |
211 | 211 | } |
212 | 212 | // we don't need to do something in this recursive branch |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | // now path stack is empty — we reached target value of given path in source argument |
218 | 218 | // so if result is multiple |
219 | - if(is_array($result)) { |
|
219 | + if (is_array($result)) { |
|
220 | 220 | // we append source to result |
221 | 221 | $result[] = $source; |
222 | 222 | } else { |
@@ -243,8 +243,8 @@ discard block |
||
243 | 243 | $tempPrevKey = null; |
244 | 244 | |
245 | 245 | // let's iterate every path part to go deeper into nesting |
246 | - foreach($path as $key) { |
|
247 | - if(isset($temp) && is_scalar($temp)) { |
|
246 | + foreach ($path as $key) { |
|
247 | + if (isset($temp) && is_scalar($temp)) { |
|
248 | 248 | // value in the middle of the path must be an array |
249 | 249 | $temp = []; |
250 | 250 | } |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | $tempPrevKey = $key; |
254 | 254 | |
255 | 255 | // go to the next nested level |
256 | - if(is_object($temp)) { |
|
257 | - if($strict && !($temp instanceof stdClass) && !ObjectAccessor::hasPublicProperty($temp, $key)) { |
|
256 | + if (is_object($temp)) { |
|
257 | + if ($strict && !($temp instanceof stdClass) && !ObjectAccessor::hasPublicProperty($temp, $key)) { |
|
258 | 258 | throw NestedAccessorException::createAsCannotSetValue($mode, implode($this->pathDelimiter, $path)); |
259 | 259 | } |
260 | 260 | $temp = &$temp->{$key}; |
@@ -265,18 +265,18 @@ discard block |
||
265 | 265 | } |
266 | 266 | } |
267 | 267 | // now we can save value to the source |
268 | - switch($mode) { |
|
268 | + switch ($mode) { |
|
269 | 269 | case self::SET_MODE_SET: |
270 | 270 | $temp = $value; |
271 | 271 | break; |
272 | 272 | case self::SET_MODE_APPEND: |
273 | - if(!is_array($temp) || ArrayHelper::isAssoc($temp)) { |
|
274 | - if($strict) { |
|
273 | + if (!is_array($temp) || ArrayHelper::isAssoc($temp)) { |
|
274 | + if ($strict) { |
|
275 | 275 | throw NestedAccessorException::createAsCannotSetValue( |
276 | 276 | $mode, |
277 | 277 | implode($this->pathDelimiter, $path) |
278 | 278 | ); |
279 | - } elseif(!is_array($temp)) { |
|
279 | + } elseif (!is_array($temp)) { |
|
280 | 280 | $temp = []; |
281 | 281 | } |
282 | 282 | } |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | $temp[] = $value; |
285 | 285 | break; |
286 | 286 | case self::SET_MODE_DELETE: |
287 | - if($tempPrevKey === null || (!is_array($tempPrevSource) && !($tempPrevSource instanceof stdClass))) { |
|
288 | - if($strict) { |
|
287 | + if ($tempPrevKey === null || (!is_array($tempPrevSource) && !($tempPrevSource instanceof stdClass))) { |
|
288 | + if ($strict) { |
|
289 | 289 | throw NestedAccessorException::createAsCannotSetValue( |
290 | 290 | $mode, |
291 | 291 | implode($this->pathDelimiter, $path) |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | return $this; |
295 | 295 | } |
296 | 296 | } |
297 | - if(is_array($tempPrevSource)) { |
|
297 | + if (is_array($tempPrevSource)) { |
|
298 | 298 | unset($tempPrevSource[$tempPrevKey]); |
299 | 299 | } else { |
300 | 300 | unset($tempPrevSource->{$tempPrevKey}); |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | */ |
313 | 313 | protected function formatPath($path): array |
314 | 314 | { |
315 | - if(is_array($path)) { |
|
315 | + if (is_array($path)) { |
|
316 | 316 | return $path; |
317 | 317 | } |
318 | 318 | |
319 | - if($path === null || $path === '') { |
|
319 | + if ($path === null || $path === '') { |
|
320 | 320 | return []; |
321 | 321 | } |
322 | 322 |