Passed
Push — master ( 1fd154...475181 )
by Smoren
01:40
created
src/Components/NestedAccessor.php 1 patch
Spacing   +24 added lines, -24 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
 
@@ -64,12 +64,12 @@  discard block
 block discarded – undo
64 64
     public function get($path = null, bool $strict = true)
65 65
     {
66 66
         // when path is not specified
67
-        if($path === null || $path === '') {
67
+        if ($path === null || $path === '') {
68 68
             // let's return the full source
69 69
             return $this->source;
70 70
         }
71 71
 
72
-        if(!is_array($path)) {
72
+        if (!is_array($path)) {
73 73
             $path = explode($this->pathDelimiter, $path);
74 74
         }
75 75
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
         );
87 87
 
88 88
         // when strict mode is on and we got errors
89
-        if($strict && $errorsCount) {
89
+        if ($strict && $errorsCount) {
90 90
             throw NestedAccessorException::createAsCannotGetValue(
91 91
                 implode($this->pathDelimiter, $path),
92 92
                 $errorsCount
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function set($path, $value, bool $strict = true): self
108 108
     {
109
-        if(!is_array($path)) {
109
+        if (!is_array($path)) {
110 110
             $path = explode($this->pathDelimiter, $path);
111 111
         }
112 112
         return $this->_set($this->source, $path, $value, $strict);
@@ -123,9 +123,9 @@  discard block
 block discarded – undo
123 123
     protected function _get($source, array $path, &$result, int &$errorsCount): void
124 124
     {
125 125
         // if path stack is empty — we reached target value of given path in source argument
126
-        if(!count($path)) {
126
+        if (!count($path)) {
127 127
             // so if result is multiple
128
-            if(is_array($result)) {
128
+            if (is_array($result)) {
129 129
                 // we append source to result
130 130
                 $result[] = $source;
131 131
             } else {
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
         }
138 138
 
139 139
         // let's iterate every path part from stack
140
-        while(count($path)) {
141
-            if(is_array($source) && !ArrayHelper::isAssoc($source)) {
140
+        while (count($path)) {
141
+            if (is_array($source) && !ArrayHelper::isAssoc($source)) {
142 142
                 // the result will be multiple
143
-                if(!is_array($result)) {
143
+                if (!is_array($result)) {
144 144
                     $result = [];
145 145
                 }
146 146
                 // and we need to use recursive call for each item of this array
147
-                foreach($source as $item) {
147
+                foreach ($source as $item) {
148 148
                     $this->_get($item, $path, $result, $errorsCount);
149 149
                 }
150 150
                 // we don't need to do something in this recursive branch
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
 
154 154
             $key = array_pop($path);
155 155
 
156
-            if(is_array($source)) {
157
-                if(!array_key_exists($key, $source)) {
156
+            if (is_array($source)) {
157
+                if (!array_key_exists($key, $source)) {
158 158
                     // path part key is missing in source array
159 159
                     $errorsCount++;
160 160
                     // we cannot go deeper
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
                 }
163 163
                 // go to the next nested level
164 164
                 $source = $source[$key];
165
-            } elseif(is_object($source)) {
165
+            } elseif (is_object($source)) {
166 166
                 $getterName = 'get'.ucfirst($key);
167
-                if(method_exists($source, $getterName)) {
167
+                if (method_exists($source, $getterName)) {
168 168
                     // go to the next nested level
169 169
                     $source = $source->{$getterName}();
170
-                } elseif(property_exists($source, $key)) {
170
+                } elseif (property_exists($source, $key)) {
171 171
                     // go to the next nested level
172 172
                     $source = $source->{$key};
173 173
                 } else {
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 
186 186
             // when it's not the last iteration of the stack
187 187
             // and the source is non-associative array (list)
188
-            if(count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) {
188
+            if (count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) {
189 189
                 // the result will be multiple
190
-                if(!is_array($result)) {
190
+                if (!is_array($result)) {
191 191
                     $result = [];
192 192
                 }
193 193
                 // and we need to use recursive call for each item of this array
194
-                foreach($source as $item) {
194
+                foreach ($source as $item) {
195 195
                     $this->_get($item, $path, $result, $errorsCount);
196 196
                 }
197 197
                 // we don't need to do something in this recursive branch
@@ -217,15 +217,15 @@  discard block
 block discarded – undo
217 217
     {
218 218
         $temp = &$source;
219 219
         // let's iterate every path part to go deeper into nesting
220
-        foreach($path as $key) {
221
-            if(isset($temp) && is_scalar($temp)) {
220
+        foreach ($path as $key) {
221
+            if (isset($temp) && is_scalar($temp)) {
222 222
                 // value in the middle of the path must me an array
223 223
                 $temp = [];
224 224
             }
225 225
 
226 226
             // go to the next nested level
227
-            if(is_object($temp)) {
228
-                if($strict && !property_exists($temp, $key)) {
227
+            if (is_object($temp)) {
228
+                if ($strict && !property_exists($temp, $key)) {
229 229
                     throw NestedAccessorException::createAsCannotSetValue($key);
230 230
                 }
231 231
                 $temp = &$temp->{$key};
Please login to merge, or discard this patch.