@@ -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,14 +123,14 @@ discard block |
||
123 | 123 | protected function _get($source, array $path, &$result, int &$errorsCount): void |
124 | 124 | { |
125 | 125 | // let's iterate every path part from stack |
126 | - while(count($path)) { |
|
127 | - if(is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
126 | + while (count($path)) { |
|
127 | + if (is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
128 | 128 | // the result will be multiple |
129 | - if(!is_array($result)) { |
|
129 | + if (!is_array($result)) { |
|
130 | 130 | $result = []; |
131 | 131 | } |
132 | 132 | // and we need to use recursive call for each item of this array |
133 | - foreach($source as $item) { |
|
133 | + foreach ($source as $item) { |
|
134 | 134 | $this->_get($item, $path, $result, $errorsCount); |
135 | 135 | } |
136 | 136 | // we don't need to do something in this recursive branch |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | |
140 | 140 | $key = array_pop($path); |
141 | 141 | |
142 | - if(is_array($source)) { |
|
143 | - if(!array_key_exists($key, $source)) { |
|
142 | + if (is_array($source)) { |
|
143 | + if (!array_key_exists($key, $source)) { |
|
144 | 144 | // path part key is missing in source array |
145 | 145 | $errorsCount++; |
146 | 146 | // we cannot go deeper |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | } |
149 | 149 | // go to the next nested level |
150 | 150 | $source = $source[$key]; |
151 | - } elseif(is_object($source)) { |
|
151 | + } elseif (is_object($source)) { |
|
152 | 152 | $getterName = 'get'.ucfirst($key); |
153 | - if(method_exists($source, $getterName)) { |
|
153 | + if (method_exists($source, $getterName)) { |
|
154 | 154 | // go to the next nested level |
155 | 155 | $source = $source->{$getterName}(); |
156 | - } elseif(property_exists($source, $key)) { |
|
156 | + } elseif (property_exists($source, $key)) { |
|
157 | 157 | // go to the next nested level |
158 | 158 | $source = $source->{$key}; |
159 | 159 | } else { |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | |
172 | 172 | // when it's not the last iteration of the stack |
173 | 173 | // and the source is non-associative array (list) |
174 | - if(count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
174 | + if (count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
175 | 175 | // the result will be multiple |
176 | - if(!is_array($result)) { |
|
176 | + if (!is_array($result)) { |
|
177 | 177 | $result = []; |
178 | 178 | } |
179 | 179 | // and we need to use recursive call for each item of this array |
180 | - foreach($source as $item) { |
|
180 | + foreach ($source as $item) { |
|
181 | 181 | $this->_get($item, $path, $result, $errorsCount); |
182 | 182 | } |
183 | 183 | // we don't need to do something in this recursive branch |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | // now path stack is empty — we reached target value of given path in source argument |
189 | 189 | // so if result is multiple |
190 | - if(is_array($result)) { |
|
190 | + if (is_array($result)) { |
|
191 | 191 | // we append source to result |
192 | 192 | $result[] = $source; |
193 | 193 | } else { |
@@ -210,15 +210,15 @@ discard block |
||
210 | 210 | { |
211 | 211 | $temp = &$source; |
212 | 212 | // let's iterate every path part to go deeper into nesting |
213 | - foreach($path as $key) { |
|
214 | - if(isset($temp) && is_scalar($temp)) { |
|
213 | + foreach ($path as $key) { |
|
214 | + if (isset($temp) && is_scalar($temp)) { |
|
215 | 215 | // value in the middle of the path must me an array |
216 | 216 | $temp = []; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // go to the next nested level |
220 | - if(is_object($temp)) { |
|
221 | - if($strict && !property_exists($temp, $key)) { |
|
220 | + if (is_object($temp)) { |
|
221 | + if ($strict && !property_exists($temp, $key)) { |
|
222 | 222 | throw NestedAccessorException::createAsCannotSetValue($key); |
223 | 223 | } |
224 | 224 | $temp = &$temp->{$key}; |