@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function __construct(&$source, string $pathDelimiter = '.') |
| 31 | 31 | { |
| 32 | - if($source === null) { |
|
| 32 | + if ($source === null) { |
|
| 33 | 33 | $source = []; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if(is_scalar($source)) { |
|
| 36 | + if (is_scalar($source)) { |
|
| 37 | 37 | throw NestedAccessorException::createAsSourceIsScalar($source); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | public function get($path = null, bool $strict = true) |
| 53 | 53 | { |
| 54 | 54 | // when path is not specified |
| 55 | - if($path === null || $path === '') { |
|
| 55 | + if ($path === null || $path === '') { |
|
| 56 | 56 | // let's return the full source |
| 57 | 57 | return $this->source; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if(!is_array($path)) { |
|
| 60 | + if (!is_array($path)) { |
|
| 61 | 61 | $path = explode($this->pathDelimiter, $path); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | ); |
| 75 | 75 | |
| 76 | 76 | // when strict mode is on and we got errors |
| 77 | - if($strict && $errorsCount) { |
|
| 77 | + if ($strict && $errorsCount) { |
|
| 78 | 78 | throw NestedAccessorException::createAsCannotGetValue( |
| 79 | 79 | implode($this->pathDelimiter, $path), |
| 80 | 80 | $errorsCount |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public function set($path, $value, bool $strict = true): self |
| 96 | 96 | { |
| 97 | - if(!is_array($path)) { |
|
| 97 | + if (!is_array($path)) { |
|
| 98 | 98 | $path = explode($this->pathDelimiter, $path); |
| 99 | 99 | } |
| 100 | 100 | return $this->_set($this->source, $path, $value, $strict); |
@@ -111,9 +111,9 @@ discard block |
||
| 111 | 111 | protected function _get($source, array $path, &$result, int &$errorsCount): void |
| 112 | 112 | { |
| 113 | 113 | // if path stack is empty — we reached target value of given path in source argument |
| 114 | - if(!count($path)) { |
|
| 114 | + if (!count($path)) { |
|
| 115 | 115 | // so if result is multiple |
| 116 | - if(is_array($result)) { |
|
| 116 | + if (is_array($result)) { |
|
| 117 | 117 | // we append source to result |
| 118 | 118 | $result[] = $source; |
| 119 | 119 | } else { |
@@ -125,11 +125,11 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // let's iterate every path part from stack |
| 128 | - while(count($path)) { |
|
| 128 | + while (count($path)) { |
|
| 129 | 129 | $key = array_pop($path); |
| 130 | 130 | |
| 131 | - if(is_array($source)) { |
|
| 132 | - if(!array_key_exists($key, $source)) { |
|
| 131 | + if (is_array($source)) { |
|
| 132 | + if (!array_key_exists($key, $source)) { |
|
| 133 | 133 | // path part key is missing in source array |
| 134 | 134 | $errorsCount++; |
| 135 | 135 | // we cannot go deeper |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | } |
| 138 | 138 | // go to the next nested level |
| 139 | 139 | $source = $source[$key]; |
| 140 | - } elseif(is_object($source)) { |
|
| 141 | - if(!property_exists($source, $key)) { |
|
| 140 | + } elseif (is_object($source)) { |
|
| 141 | + if (!property_exists($source, $key)) { |
|
| 142 | 142 | // path part key is missing in source object |
| 143 | 143 | $errorsCount++; |
| 144 | 144 | // we cannot go deeper |
@@ -155,13 +155,13 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | // when it's not the last iteration of the stack |
| 157 | 157 | // and the source is non-associative array (list) |
| 158 | - if(count($path) && is_array($source) && !ArrHelper::isAssoc($source)) { |
|
| 158 | + if (count($path) && is_array($source) && !ArrHelper::isAssoc($source)) { |
|
| 159 | 159 | // the result will be multiple |
| 160 | - if(!is_array($result)) { |
|
| 160 | + if (!is_array($result)) { |
|
| 161 | 161 | $result = []; |
| 162 | 162 | } |
| 163 | 163 | // and we need to use recursive call for each item of this array |
| 164 | - foreach($source as $item) { |
|
| 164 | + foreach ($source as $item) { |
|
| 165 | 165 | $this->_get($item, $path, $result, $errorsCount); |
| 166 | 166 | } |
| 167 | 167 | // we don't need to do something in this recursive branch |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | { |
| 188 | 188 | $temp = &$source; |
| 189 | 189 | // let's iterate every path part to go deeper into nesting |
| 190 | - foreach($path as $key) { |
|
| 191 | - if(isset($temp) && is_scalar($temp)) { |
|
| 190 | + foreach ($path as $key) { |
|
| 191 | + if (isset($temp) && is_scalar($temp)) { |
|
| 192 | 192 | // value in the middle of the path must me an array |
| 193 | 193 | $temp = []; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // go to the next nested level |
| 197 | - if(is_object($temp)) { |
|
| 198 | - if($strict && !property_exists($temp, $key)) { |
|
| 197 | + if (is_object($temp)) { |
|
| 198 | + if ($strict && !property_exists($temp, $key)) { |
|
| 199 | 199 | throw NestedAccessorException::createAsCannotSetValue($key); |
| 200 | 200 | } |
| 201 | 201 | $temp = &$temp->{$key}; |