@@ -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,11 +137,11 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // let's iterate every path part from stack |
| 140 | - while(count($path)) { |
|
| 140 | + while (count($path)) { |
|
| 141 | 141 | $key = array_pop($path); |
| 142 | 142 | |
| 143 | - if(is_array($source)) { |
|
| 144 | - if(!array_key_exists($key, $source)) { |
|
| 143 | + if (is_array($source)) { |
|
| 144 | + if (!array_key_exists($key, $source)) { |
|
| 145 | 145 | // path part key is missing in source array |
| 146 | 146 | $errorsCount++; |
| 147 | 147 | // we cannot go deeper |
@@ -149,8 +149,8 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | // go to the next nested level |
| 151 | 151 | $source = $source[$key]; |
| 152 | - } elseif(is_object($source)) { |
|
| 153 | - if(!property_exists($source, $key)) { |
|
| 152 | + } elseif (is_object($source)) { |
|
| 153 | + if (!property_exists($source, $key)) { |
|
| 154 | 154 | // path part key is missing in source object |
| 155 | 155 | $errorsCount++; |
| 156 | 156 | // we cannot go deeper |
@@ -167,13 +167,13 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | // when it's not the last iteration of the stack |
| 169 | 169 | // and the source is non-associative array (list) |
| 170 | - if(count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
| 170 | + if (count($path) && is_array($source) && !ArrayHelper::isAssoc($source)) { |
|
| 171 | 171 | // the result will be multiple |
| 172 | - if(!is_array($result)) { |
|
| 172 | + if (!is_array($result)) { |
|
| 173 | 173 | $result = []; |
| 174 | 174 | } |
| 175 | 175 | // and we need to use recursive call for each item of this array |
| 176 | - foreach($source as $item) { |
|
| 176 | + foreach ($source as $item) { |
|
| 177 | 177 | $this->_get($item, $path, $result, $errorsCount); |
| 178 | 178 | } |
| 179 | 179 | // we don't need to do something in this recursive branch |
@@ -199,15 +199,15 @@ discard block |
||
| 199 | 199 | { |
| 200 | 200 | $temp = &$source; |
| 201 | 201 | // let's iterate every path part to go deeper into nesting |
| 202 | - foreach($path as $key) { |
|
| 203 | - if(isset($temp) && is_scalar($temp)) { |
|
| 202 | + foreach ($path as $key) { |
|
| 203 | + if (isset($temp) && is_scalar($temp)) { |
|
| 204 | 204 | // value in the middle of the path must me an array |
| 205 | 205 | $temp = []; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // go to the next nested level |
| 209 | - if(is_object($temp)) { |
|
| 210 | - if($strict && !property_exists($temp, $key)) { |
|
| 209 | + if (is_object($temp)) { |
|
| 210 | + if ($strict && !property_exists($temp, $key)) { |
|
| 211 | 211 | throw NestedAccessorException::createAsCannotSetValue($key); |
| 212 | 212 | } |
| 213 | 213 | $temp = &$temp->{$key}; |
@@ -51,7 +51,7 @@ |
||
| 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); |
@@ -15,9 +15,9 @@ |
||
| 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 | } |