Passed
Push — master ( 47c5f2...becf08 )
by Smoren
01:38
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/Components/NestedAccessor.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
     public function setSource(&$source): void
43 43
     {
44 44
         /** @var array<scalar, mixed>|object|mixed|null $source */
45
-        if($source === null) {
45
+        if ($source === null) {
46 46
             $source = [];
47 47
         }
48 48
 
49
-        if(is_scalar($source)) {
49
+        if (is_scalar($source)) {
50 50
             throw NestedAccessorException::createAsSourceIsScalar($source);
51 51
         }
52 52
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     public function get($path = null, bool $strict = true)
61 61
     {
62 62
         // when path is not specified
63
-        if($path === null || $path === '') {
63
+        if ($path === null || $path === '') {
64 64
             // let's return the full source
65 65
             return $this->source;
66 66
         }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         );
81 81
 
82 82
         // when strict mode is on and we got errors
83
-        if($strict && $errorsCount) {
83
+        if ($strict && $errorsCount) {
84 84
             throw NestedAccessorException::createAsCannotGetValue(
85 85
                 implode($this->pathDelimiter, $path),
86 86
                 $errorsCount
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         try {
117 117
             $this->get($path);
118 118
             return true;
119
-        } catch(NestedAccessorException $e) {
119
+        } catch (NestedAccessorException $e) {
120 120
             return false;
121 121
         }
122 122
     }
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
     {
129 129
         try {
130 130
             return $this->get($path) !== null;
131
-        } catch(NestedAccessorException $e) {
131
+        } catch (NestedAccessorException $e) {
132 132
             return false;
133 133
         }
134 134
     }
@@ -144,14 +144,14 @@  discard block
 block discarded – undo
144 144
     protected function _get($source, array $path, &$result, int &$errorsCount): void
145 145
     {
146 146
         // let's iterate every path part from stack
147
-        while(count($path)) {
148
-            if(is_array($source) && !ArrayHelper::isAssoc($source)) {
147
+        while (count($path)) {
148
+            if (is_array($source) && !ArrayHelper::isAssoc($source)) {
149 149
                 // the result will be multiple
150
-                if(!is_array($result)) {
150
+                if (!is_array($result)) {
151 151
                     $result = [];
152 152
                 }
153 153
                 // and we need to use recursive call for each item of this array
154
-                foreach($source as $item) {
154
+                foreach ($source as $item) {
155 155
                     $this->_get($item, $path, $result, $errorsCount);
156 156
                 }
157 157
                 // we don't need to do something in this recursive branch
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 
161 161
             $key = array_pop($path);
162 162
 
163
-            if(is_array($source)) {
164
-                if(!array_key_exists($key, $source)) {
163
+            if (is_array($source)) {
164
+                if (!array_key_exists($key, $source)) {
165 165
                     // path part key is missing in source array
166 166
                     $errorsCount++;
167 167
                     // we cannot go deeper
@@ -169,12 +169,12 @@  discard block
 block discarded – undo
169 169
                 }
170 170
                 // go to the next nested level
171 171
                 $source = $source[$key];
172
-            } elseif(is_object($source)) {
172
+            } elseif (is_object($source)) {
173 173
                 $getterName = 'get'.ucfirst($key);
174
-                if(method_exists($source, $getterName)) {
174
+                if (method_exists($source, $getterName)) {
175 175
                     // go to the next nested level
176 176
                     $source = $source->{$getterName}();
177
-                } elseif(property_exists($source, $key)) {
177
+                } elseif (property_exists($source, $key)) {
178 178
                     // go to the next nested level
179 179
                     $source = $source->{$key};
180 180
                 } else {
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
 
193 193
             // when it's not the last iteration of the stack
194 194
             // and the source is non-associative array (list)
195
-            if(count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) {
195
+            if (count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) {
196 196
                 // the result will be multiple
197
-                if(!is_array($result)) {
197
+                if (!is_array($result)) {
198 198
                     $result = [];
199 199
                 }
200 200
                 // and we need to use recursive call for each item of this array
201
-                foreach($source as $item) {
201
+                foreach ($source as $item) {
202 202
                     $this->_get($item, $path, $result, $errorsCount);
203 203
                 }
204 204
                 // we don't need to do something in this recursive branch
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 
209 209
         // now path stack is empty — we reached target value of given path in source argument
210 210
         // so if result is multiple
211
-        if(is_array($result)) {
211
+        if (is_array($result)) {
212 212
             // we append source to result
213 213
             $result[] = $source;
214 214
         } else {
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
     {
233 233
         $temp = &$source;
234 234
         // let's iterate every path part to go deeper into nesting
235
-        foreach($path as $key) {
236
-            if(isset($temp) && is_scalar($temp)) {
235
+        foreach ($path as $key) {
236
+            if (isset($temp) && is_scalar($temp)) {
237 237
                 // value in the middle of the path must me an array
238 238
                 $temp = [];
239 239
             }
240 240
 
241 241
             // go to the next nested level
242
-            if(is_object($temp)) {
243
-                if($strict && !property_exists($temp, $key)) {
242
+            if (is_object($temp)) {
243
+                if ($strict && !property_exists($temp, $key)) {
244 244
                     throw NestedAccessorException::createAsCannotSetValue(implode($this->pathDelimiter, $path));
245 245
                 }
246 246
                 $temp = &$temp->{$key};
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
             }
252 252
         }
253 253
         // now we can save value to the source
254
-        if($append) {
255
-            if(!is_array($temp) || ArrayHelper::isAssoc($temp)) {
256
-                if($strict) {
254
+        if ($append) {
255
+            if (!is_array($temp) || ArrayHelper::isAssoc($temp)) {
256
+                if ($strict) {
257 257
                     throw NestedAccessorException::createAsCannotSetValue(implode($this->pathDelimiter, $path));
258
-                } elseif(!is_array($temp)) {
258
+                } elseif (!is_array($temp)) {
259 259
                     $temp = [];
260 260
                 }
261 261
             }
@@ -275,11 +275,11 @@  discard block
 block discarded – undo
275 275
      */
276 276
     protected function formatPath($path): array
277 277
     {
278
-        if(is_array($path)) {
278
+        if (is_array($path)) {
279 279
             return $path;
280 280
         }
281 281
 
282
-        if($path === null || $path === '') {
282
+        if ($path === null || $path === '') {
283 283
             return [];
284 284
         }
285 285
 
Please login to merge, or discard this patch.