@@ -42,11 +42,11 @@ discard block |
||
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,7 +64,7 @@ discard block |
||
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 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | ); |
85 | 85 | |
86 | 86 | // when strict mode is on and we got errors |
87 | - if($strict && $errorsCount) { |
|
87 | + if ($strict && $errorsCount) { |
|
88 | 88 | throw NestedAccessorException::createAsCannotGetValue( |
89 | 89 | implode($this->pathDelimiter, $path), |
90 | 90 | $errorsCount |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | protected function _get($source, array $path, &$result, int &$errorsCount): void |
134 | 134 | { |
135 | 135 | // let's iterate every path part from stack |
136 | - while(count($path)) { |
|
137 | - if(is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
136 | + while (count($path)) { |
|
137 | + if (is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
138 | 138 | // the result will be multiple |
139 | - if(!is_array($result)) { |
|
139 | + if (!is_array($result)) { |
|
140 | 140 | $result = []; |
141 | 141 | } |
142 | 142 | // and we need to use recursive call for each item of this array |
143 | - foreach($source as $item) { |
|
143 | + foreach ($source as $item) { |
|
144 | 144 | $this->_get($item, $path, $result, $errorsCount); |
145 | 145 | } |
146 | 146 | // we don't need to do something in this recursive branch |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | |
150 | 150 | $key = array_pop($path); |
151 | 151 | |
152 | - if(is_array($source)) { |
|
153 | - if(!array_key_exists($key, $source)) { |
|
152 | + if (is_array($source)) { |
|
153 | + if (!array_key_exists($key, $source)) { |
|
154 | 154 | // path part key is missing in source array |
155 | 155 | $errorsCount++; |
156 | 156 | // we cannot go deeper |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | } |
159 | 159 | // go to the next nested level |
160 | 160 | $source = $source[$key]; |
161 | - } elseif(is_object($source)) { |
|
161 | + } elseif (is_object($source)) { |
|
162 | 162 | $getterName = 'get'.ucfirst($key); |
163 | - if(method_exists($source, $getterName)) { |
|
163 | + if (method_exists($source, $getterName)) { |
|
164 | 164 | // go to the next nested level |
165 | 165 | $source = $source->{$getterName}(); |
166 | - } elseif(property_exists($source, $key)) { |
|
166 | + } elseif (property_exists($source, $key)) { |
|
167 | 167 | // go to the next nested level |
168 | 168 | $source = $source->{$key}; |
169 | 169 | } else { |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | |
182 | 182 | // when it's not the last iteration of the stack |
183 | 183 | // and the source is non-associative array (list) |
184 | - if(count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
184 | + if (count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
185 | 185 | // the result will be multiple |
186 | - if(!is_array($result)) { |
|
186 | + if (!is_array($result)) { |
|
187 | 187 | $result = []; |
188 | 188 | } |
189 | 189 | // and we need to use recursive call for each item of this array |
190 | - foreach($source as $item) { |
|
190 | + foreach ($source as $item) { |
|
191 | 191 | $this->_get($item, $path, $result, $errorsCount); |
192 | 192 | } |
193 | 193 | // we don't need to do something in this recursive branch |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | // now path stack is empty — we reached target value of given path in source argument |
199 | 199 | // so if result is multiple |
200 | - if(is_array($result)) { |
|
200 | + if (is_array($result)) { |
|
201 | 201 | // we append source to result |
202 | 202 | $result[] = $source; |
203 | 203 | } else { |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | { |
222 | 222 | $temp = &$source; |
223 | 223 | // let's iterate every path part to go deeper into nesting |
224 | - foreach($path as $key) { |
|
225 | - if(isset($temp) && is_scalar($temp)) { |
|
224 | + foreach ($path as $key) { |
|
225 | + if (isset($temp) && is_scalar($temp)) { |
|
226 | 226 | // value in the middle of the path must me an array |
227 | 227 | $temp = []; |
228 | 228 | } |
229 | 229 | |
230 | 230 | // go to the next nested level |
231 | - if(is_object($temp)) { |
|
232 | - if($strict && !property_exists($temp, $key)) { |
|
231 | + if (is_object($temp)) { |
|
232 | + if ($strict && !property_exists($temp, $key)) { |
|
233 | 233 | throw NestedAccessorException::createAsCannotSetValue(implode($this->pathDelimiter, $path)); |
234 | 234 | } |
235 | 235 | $temp = &$temp->{$key}; |
@@ -240,11 +240,11 @@ discard block |
||
240 | 240 | } |
241 | 241 | } |
242 | 242 | // now we can save value to the source |
243 | - if($append) { |
|
244 | - if(!is_array($temp) || ArrayHelper::isAssoc($temp)) { |
|
245 | - if($strict) { |
|
243 | + if ($append) { |
|
244 | + if (!is_array($temp) || ArrayHelper::isAssoc($temp)) { |
|
245 | + if ($strict) { |
|
246 | 246 | throw NestedAccessorException::createAsCannotSetValue(implode($this->pathDelimiter, $path)); |
247 | - } elseif(!is_array($temp)) { |
|
247 | + } elseif (!is_array($temp)) { |
|
248 | 248 | $temp = []; |
249 | 249 | } |
250 | 250 | } |
@@ -264,11 +264,11 @@ discard block |
||
264 | 264 | */ |
265 | 265 | protected function formatPath($path): array |
266 | 266 | { |
267 | - if(is_array($path)) { |
|
267 | + if (is_array($path)) { |
|
268 | 268 | return $path; |
269 | 269 | } |
270 | 270 | |
271 | - if($path === null || $path === '') { |
|
271 | + if ($path === null || $path === '') { |
|
272 | 272 | return []; |
273 | 273 | } |
274 | 274 |