| Conditions | 12 |
| Paths | 16 |
| Total Lines | 35 |
| Code Lines | 21 |
| 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 |
||
| 110 | private function getDirtyFields(array $newSerializedModel, array $oldSerializedModel, ClassMetadata $classMetadata = null) |
||
| 111 | { |
||
| 112 | $dirtyFields = []; |
||
| 113 | |||
| 114 | foreach ($newSerializedModel as $key => $value) { |
||
| 115 | if (array_key_exists($key, $oldSerializedModel)) { |
||
| 116 | if (is_array($value)) { |
||
| 117 | $currentClassMetadata = $classMetadata->getRelation($key) ? $this->mapping->getClassMetadata($classMetadata->getRelation($key)->getTargetEntity()) : null; |
||
| 118 | $idSerializedKey = $currentClassMetadata ? $currentClassMetadata->getIdSerializeKey() : null; |
||
| 119 | $recursiveDiff = $this->getDirtyFields($value, $oldSerializedModel[$key], $currentClassMetadata); |
||
| 120 | if (count($recursiveDiff)) { |
||
| 121 | $dirtyFields[$key] = $this->addIdentifiers($value, $recursiveDiff, $idSerializedKey); |
||
| 122 | |||
| 123 | // if theres only ids not objects, keep them |
||
| 124 | foreach ($value as $valueKey => $valueId) { |
||
| 125 | if (is_string($valueId) && is_int($valueKey)) { |
||
| 126 | $dirtyFields[$key][$valueKey] = $valueId; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | } elseif (count($value) != count($oldSerializedModel[$key])) { |
||
| 130 | // get all objects ids of new array |
||
| 131 | $dirtyFields[$key] = $this->addIdentifiers($value, [], $idSerializedKey); |
||
| 132 | } |
||
| 133 | } else { |
||
| 134 | if ($value != $oldSerializedModel[$key]) { |
||
| 135 | $dirtyFields[$key] = $value; |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } else { |
||
| 139 | $dirtyFields[$key] = $value; |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | return $dirtyFields; |
||
| 144 | } |
||
| 145 | |||
| 169 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.