| Conditions | 12 |
| Paths | 14 |
| Total Lines | 42 |
| Code Lines | 25 |
| 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 |
||
| 14 | private function arrayRecursiveDiff($newModel, $oldModel, $isInDepth = false) |
||
| 15 | { |
||
| 16 | $diff = []; |
||
| 17 | $hasDiff = false; |
||
| 18 | |||
| 19 | foreach ($newModel as $key => $value) { |
||
| 20 | if (array_key_exists($key, $oldModel)) { |
||
| 21 | if (is_array($value)) { |
||
| 22 | $recursiveDiff = $this->arrayRecursiveDiff($value, $oldModel[$key], true); |
||
| 23 | if (count($recursiveDiff)) { |
||
| 24 | $hasDiff = true; |
||
| 25 | $diff[$key] = $recursiveDiff; |
||
| 26 | |||
| 27 | //if theres only ids, keep them |
||
| 28 | foreach ($value as $valueKey => $valueId) { |
||
| 29 | if (is_string($valueId) && is_int($valueKey)) { |
||
| 30 | $diff[$key][$valueKey] = $valueId; |
||
| 31 | } |
||
| 32 | } |
||
| 33 | } elseif (count($value) != count($oldModel[$key])) { |
||
| 34 | $hasDiff = true; |
||
| 35 | //get all objects ids of new array |
||
| 36 | $diff[$key] = []; |
||
| 37 | $diff[$key] = $this->addIds($value, $diff[$key]); |
||
| 38 | } |
||
| 39 | } else { |
||
| 40 | if ($value != $oldModel[$key]) { |
||
| 41 | $diff[$key] = $value; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | } else { |
||
| 45 | $diff[$key] = $value; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($isInDepth && $hasDiff) { |
||
| 50 | // in depth add ids of modified objects |
||
| 51 | $diff = $this->addIds($newModel, $diff); |
||
| 52 | } |
||
| 53 | |||
| 54 | return $diff; |
||
| 55 | } |
||
| 56 | |||
| 102 |