Passed
Push — master ( 72f38a...596bea )
by Smoren
02:21
created
src/Helpers/NestedHelper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@
 block discarded – undo
51 51
      */
52 52
     protected static function prepareAccessor(&$source): NestedAccessor
53 53
     {
54
-        if(static::$accessor === null) {
54
+        if (static::$accessor === null) {
55 55
             static::$accessor = new NestedAccessor($source);
56 56
         } else {
57 57
             static::$accessor->setSource($source);
Please login to merge, or discard this patch.
src/Helpers/ArrayHelper.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@
 block discarded – undo
15 15
      */
16 16
     public static function isAssoc(array $input): bool
17 17
     {
18
-        if([] === $input) {
18
+        if ([] === $input) {
19 19
             return false;
20 20
         }
21
-        return array_keys($input) !== range(0, count($input) - 1);
21
+        return array_keys($input) !== range(0, count($input)-1);
22 22
     }
23 23
 }
Please login to merge, or discard this patch.
src/Exceptions/NestedAccessorException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
      */
63 63
     public static function createAsCannotSetValue(int $mode, string $path): NestedAccessorException
64 64
     {
65
-        switch($mode) {
65
+        switch ($mode) {
66 66
             case NestedAccessor::SET_MODE_SET:
67 67
                 return static::_createAsCannotSetValue($path);
68 68
             case NestedAccessor::SET_MODE_APPEND:
Please login to merge, or discard this patch.
src/Components/NestedAccessor.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
     public function setSource(&$source): void
48 48
     {
49 49
         /** @var array<scalar, mixed>|object|mixed|null $source */
50
-        if($source === null) {
50
+        if ($source === null) {
51 51
             $source = [];
52 52
         }
53 53
 
54
-        if(is_scalar($source)) {
54
+        if (is_scalar($source)) {
55 55
             throw NestedAccessorException::createAsSourceIsScalar($source);
56 56
         }
57 57
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     public function get($path = null, bool $strict = true)
66 66
     {
67 67
         // when path is not specified
68
-        if($path === null || $path === '') {
68
+        if ($path === null || $path === '') {
69 69
             // let's return the full source
70 70
             return $this->source;
71 71
         }
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         );
86 86
 
87 87
         // when strict mode is on and we got errors
88
-        if($strict && $errorsCount) {
88
+        if ($strict && $errorsCount) {
89 89
             throw NestedAccessorException::createAsCannotGetValue(
90 90
                 implode($this->pathDelimiter, $path),
91 91
                 $errorsCount
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
     {
121 121
         $path = $this->formatPath($path);
122 122
 
123
-        if(!$this->exist($path)) {
124
-            if($strict) {
123
+        if (!$this->exist($path)) {
124
+            if ($strict) {
125 125
                 throw NestedAccessorException::createAsCannotSetValue(
126 126
                     self::SET_MODE_DELETE,
127 127
                     implode($this->pathDelimiter, $path)
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         try {
142 142
             $this->get($path);
143 143
             return true;
144
-        } catch(NestedAccessorException $e) {
144
+        } catch (NestedAccessorException $e) {
145 145
             return false;
146 146
         }
147 147
     }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
     {
154 154
         try {
155 155
             return $this->get($path) !== null;
156
-        } catch(NestedAccessorException $e) {
156
+        } catch (NestedAccessorException $e) {
157 157
             return false;
158 158
         }
159 159
     }
@@ -169,14 +169,14 @@  discard block
 block discarded – undo
169 169
     protected function _get($source, array $path, &$result, int &$errorsCount): void
170 170
     {
171 171
         // let's iterate every path part from stack
172
-        while(count($path)) {
173
-            if(is_array($source) && !ArrayHelper::isAssoc($source)) {
172
+        while (count($path)) {
173
+            if (is_array($source) && !ArrayHelper::isAssoc($source)) {
174 174
                 // the result will be multiple
175
-                if(!is_array($result)) {
175
+                if (!is_array($result)) {
176 176
                     $result = [];
177 177
                 }
178 178
                 // and we need to use recursive call for each item of this array
179
-                foreach($source as $item) {
179
+                foreach ($source as $item) {
180 180
                     $this->_get($item, $path, $result, $errorsCount);
181 181
                 }
182 182
                 // we don't need to do something in this recursive branch
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 
186 186
             $key = array_pop($path);
187 187
 
188
-            if(is_array($source)) {
189
-                if(!array_key_exists($key, $source)) {
188
+            if (is_array($source)) {
189
+                if (!array_key_exists($key, $source)) {
190 190
                     // path part key is missing in source array
191 191
                     $errorsCount++;
192 192
                     // we cannot go deeper
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
                 }
195 195
                 // go to the next nested level
196 196
                 $source = $source[$key];
197
-            } elseif(is_object($source)) {
197
+            } elseif (is_object($source)) {
198 198
                 $getterName = 'get'.ucfirst($key);
199
-                if(method_exists($source, $getterName)) {
199
+                if (method_exists($source, $getterName)) {
200 200
                     // go to the next nested level
201 201
                     $source = $source->{$getterName}();
202
-                } elseif(property_exists($source, $key)) {
202
+                } elseif (property_exists($source, $key)) {
203 203
                     // go to the next nested level
204 204
                     $source = $source->{$key};
205 205
                 } else {
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 
218 218
             // when it's not the last iteration of the stack
219 219
             // and the source is non-associative array (list)
220
-            if(count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) {
220
+            if (count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) {
221 221
                 // the result will be multiple
222
-                if(!is_array($result)) {
222
+                if (!is_array($result)) {
223 223
                     $result = [];
224 224
                 }
225 225
                 // and we need to use recursive call for each item of this array
226
-                foreach($source as $item) {
226
+                foreach ($source as $item) {
227 227
                     $this->_get($item, $path, $result, $errorsCount);
228 228
                 }
229 229
                 // we don't need to do something in this recursive branch
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 
234 234
         // now path stack is empty — we reached target value of given path in source argument
235 235
         // so if result is multiple
236
-        if(is_array($result)) {
236
+        if (is_array($result)) {
237 237
             // we append source to result
238 238
             $result[] = $source;
239 239
         } else {
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
         $tempPrevKey = null;
261 261
 
262 262
         // let's iterate every path part to go deeper into nesting
263
-        foreach($path as $key) {
264
-            if(isset($temp) && is_scalar($temp)) {
263
+        foreach ($path as $key) {
264
+            if (isset($temp) && is_scalar($temp)) {
265 265
                 // value in the middle of the path must be an array
266 266
                 $temp = [];
267 267
             }
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
             $tempPrevKey = $key;
271 271
 
272 272
             // go to the next nested level
273
-            if(is_object($temp)) {
274
-                if($strict && !property_exists($temp, $key)) {
273
+            if (is_object($temp)) {
274
+                if ($strict && !property_exists($temp, $key)) {
275 275
                     throw NestedAccessorException::createAsCannotSetValue($mode, implode($this->pathDelimiter, $path));
276 276
                 }
277 277
                 $temp = &$temp->{$key};
@@ -282,18 +282,18 @@  discard block
 block discarded – undo
282 282
             }
283 283
         }
284 284
         // now we can save value to the source
285
-        switch($mode) {
285
+        switch ($mode) {
286 286
             case self::SET_MODE_SET:
287 287
                 $temp = $value;
288 288
                 break;
289 289
             case self::SET_MODE_APPEND:
290
-                if(!is_array($temp) || ArrayHelper::isAssoc($temp)) {
291
-                    if($strict) {
290
+                if (!is_array($temp) || ArrayHelper::isAssoc($temp)) {
291
+                    if ($strict) {
292 292
                         throw NestedAccessorException::createAsCannotSetValue(
293 293
                             $mode,
294 294
                             implode($this->pathDelimiter, $path)
295 295
                         );
296
-                    } elseif(!is_array($temp)) {
296
+                    } elseif (!is_array($temp)) {
297 297
                         $temp = [];
298 298
                     }
299 299
                 }
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
                 $temp[] = $value;
302 302
                 break;
303 303
             case self::SET_MODE_DELETE:
304
-                if($tempPrevKey === null || (!is_array($tempPrevSource) && !($tempPrevSource instanceof stdClass))) {
305
-                    if($strict) {
304
+                if ($tempPrevKey === null || (!is_array($tempPrevSource) && !($tempPrevSource instanceof stdClass))) {
305
+                    if ($strict) {
306 306
                         throw NestedAccessorException::createAsCannotSetValue(
307 307
                             $mode,
308 308
                             implode($this->pathDelimiter, $path)
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                         return $this;
312 312
                     }
313 313
                 }
314
-                if(is_array($tempPrevSource)) {
314
+                if (is_array($tempPrevSource)) {
315 315
                     unset($tempPrevSource[$tempPrevKey]);
316 316
                 } else {
317 317
                     unset($tempPrevSource->{$tempPrevKey});
@@ -329,11 +329,11 @@  discard block
 block discarded – undo
329 329
      */
330 330
     protected function formatPath($path): array
331 331
     {
332
-        if(is_array($path)) {
332
+        if (is_array($path)) {
333 333
             return $path;
334 334
         }
335 335
 
336
-        if($path === null || $path === '') {
336
+        if ($path === null || $path === '') {
337 337
             return [];
338 338
         }
339 339
 
Please login to merge, or discard this patch.