Conditions | 12 |
Paths | 16 |
Total Lines | 37 |
Code Lines | 23 |
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 |
||
104 | private function getDirtyFields(array $newSerializedModel, array $oldSerializedModel, ClassMetadata $classMetadata = null) |
||
105 | { |
||
106 | $dirtyFields = []; |
||
107 | |||
108 | foreach ($newSerializedModel as $key => $value) { |
||
109 | if (array_key_exists($key, $oldSerializedModel)) { |
||
110 | if (is_array($value)) { |
||
111 | $currentClassMetadata = $classMetadata->getRelation($key) ? $this->mapping->getClassMetadata($classMetadata->getRelation($key)->getTargetEntity()) : null; |
||
112 | $idSerializedKey = $currentClassMetadata ? $currentClassMetadata->getIdSerializeKey() : null; |
||
113 | $recursiveDiff = $this->getDirtyFields($value, $oldSerializedModel[$key], $currentClassMetadata); |
||
114 | if (count($recursiveDiff)) { |
||
115 | $dirtyFields[$key] = $recursiveDiff; |
||
116 | $dirtyFields[$key] = $this->addIdentifiers($value, $dirtyFields[$key], $idSerializedKey); |
||
117 | |||
118 | //if theres only ids not objects, keep them |
||
119 | foreach ($value as $valueKey => $valueId) { |
||
120 | if (is_string($valueId) && is_int($valueKey)) { |
||
121 | $dirtyFields[$key][$valueKey] = $valueId; |
||
122 | } |
||
123 | } |
||
124 | } elseif (count($value) != count($oldSerializedModel[$key])) { |
||
125 | //get all objects ids of new array |
||
126 | $dirtyFields[$key] = []; |
||
127 | $dirtyFields[$key] = $this->addIdentifiers($value, $dirtyFields[$key], $idSerializedKey); |
||
128 | } |
||
129 | } else { |
||
130 | if ($value != $oldSerializedModel[$key]) { |
||
131 | $dirtyFields[$key] = $value; |
||
132 | } |
||
133 | } |
||
134 | } else { |
||
135 | $dirtyFields[$key] = $value; |
||
136 | } |
||
137 | } |
||
138 | |||
139 | return $dirtyFields; |
||
140 | } |
||
141 | |||
163 |
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
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.