| Conditions | 18 |
| Paths | 131 |
| Total Lines | 61 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 159 | private function process($original, $new) |
||
| 160 | { |
||
| 161 | if ( |
||
| 162 | (!$original instanceof \stdClass && !is_array($original)) |
||
| 163 | || (!$new instanceof \stdClass && !is_array($new)) |
||
| 164 | ) { |
||
| 165 | if ($original !== $new) { |
||
| 166 | $this->modifiedCnt++; |
||
| 167 | $this->modifiedPaths [] = $this->path; |
||
| 168 | JsonProcessor::pushByPath($this->modifiedOriginal, $this->path, $original); |
||
| 169 | JsonProcessor::pushByPath($this->modifiedNew, $this->path, $new); |
||
| 170 | if ($this->options & self::STOP_ON_DIFF) { |
||
| 171 | return; |
||
| 172 | } |
||
| 173 | } |
||
| 174 | return $new; |
||
| 175 | } |
||
| 176 | |||
| 177 | if ( |
||
| 178 | !($this->options & self::SKIP_REARRANGE_ARRAY) |
||
| 179 | && is_array($original) && is_array($new) |
||
| 180 | ) { |
||
| 181 | $new = $this->rearrangeArray($original, $new); |
||
| 182 | } |
||
| 183 | |||
| 184 | $newArray = $new instanceof \stdClass ? get_object_vars($new) : $new; |
||
| 185 | $newOrdered = array(); |
||
| 186 | |||
| 187 | $originalKeys = $original instanceof \stdClass ? get_object_vars($original) : $original; |
||
| 188 | |||
| 189 | foreach ($originalKeys as $key => $originalValue) { |
||
| 190 | $path = $this->path; |
||
| 191 | $this->path .= '/' . urlencode($key); |
||
| 192 | |||
| 193 | if (array_key_exists($key, $newArray)) { |
||
| 194 | $newOrdered[$key] = $this->process($originalValue, $newArray[$key]); |
||
| 195 | unset($newArray[$key]); |
||
| 196 | } else { |
||
| 197 | $this->removedCnt++; |
||
| 198 | $this->removedPaths [] = $this->path; |
||
| 199 | JsonProcessor::pushByPath($this->removed, $this->path, $originalValue); |
||
| 200 | if ($this->options & self::STOP_ON_DIFF) { |
||
| 201 | return; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | $this->path = $path; |
||
| 205 | } |
||
| 206 | |||
| 207 | // additions |
||
| 208 | foreach ($newArray as $key => $value) { |
||
| 209 | $newOrdered[$key] = $value; |
||
| 210 | $path = $this->path . '/' . urlencode($key); |
||
| 211 | JsonProcessor::pushByPath($this->added, $path, $value); |
||
| 212 | $this->addedCnt++; |
||
| 213 | $this->addedPaths [] = $path; |
||
| 214 | if ($this->options & self::STOP_ON_DIFF) { |
||
| 215 | return; |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | return is_array($new) ? $newOrdered : (object)$newOrdered; |
||
| 220 | } |
||
| 307 | } |