@@ -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,12 +64,12 @@ 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 | } |
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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,8 +162,8 @@ discard block |
||
162 | 162 | } |
163 | 163 | // go to the next nested level |
164 | 164 | $source = $source[$key]; |
165 | - } elseif(is_object($source)) { |
|
166 | - if(!property_exists($source, $key)) { |
|
165 | + } elseif (is_object($source)) { |
|
166 | + if (!property_exists($source, $key)) { |
|
167 | 167 | // path part key is missing in source object |
168 | 168 | $errorsCount++; |
169 | 169 | // we cannot go deeper |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | |
181 | 181 | // when it's not the last iteration of the stack |
182 | 182 | // and the source is non-associative array (list) |
183 | - if(count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
183 | + if (count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
184 | 184 | // the result will be multiple |
185 | - if(!is_array($result)) { |
|
185 | + if (!is_array($result)) { |
|
186 | 186 | $result = []; |
187 | 187 | } |
188 | 188 | // and we need to use recursive call for each item of this array |
189 | - foreach($source as $item) { |
|
189 | + foreach ($source as $item) { |
|
190 | 190 | $this->_get($item, $path, $result, $errorsCount); |
191 | 191 | } |
192 | 192 | // we don't need to do something in this recursive branch |
@@ -212,15 +212,15 @@ discard block |
||
212 | 212 | { |
213 | 213 | $temp = &$source; |
214 | 214 | // let's iterate every path part to go deeper into nesting |
215 | - foreach($path as $key) { |
|
216 | - if(isset($temp) && is_scalar($temp)) { |
|
215 | + foreach ($path as $key) { |
|
216 | + if (isset($temp) && is_scalar($temp)) { |
|
217 | 217 | // value in the middle of the path must me an array |
218 | 218 | $temp = []; |
219 | 219 | } |
220 | 220 | |
221 | 221 | // go to the next nested level |
222 | - if(is_object($temp)) { |
|
223 | - if($strict && !property_exists($temp, $key)) { |
|
222 | + if (is_object($temp)) { |
|
223 | + if ($strict && !property_exists($temp, $key)) { |
|
224 | 224 | throw NestedAccessorException::createAsCannotSetValue($key); |
225 | 225 | } |
226 | 226 | $temp = &$temp->{$key}; |