| Conditions | 24 |
| Paths | 26 |
| Total Lines | 70 |
| 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 |
||
| 177 | public function isChanged($value, $originalData, $valueFieldMapping) |
||
| 178 | { |
||
| 179 | // EmbedMany case |
||
| 180 | if ('many' == $valueFieldMapping['embedded'] && (is_array($value) || $value instanceof \Doctrine\Common\Collections\ArrayCollection)) { |
||
| 181 | if (count($originalData) != count($value)) { |
||
| 182 | return true; |
||
| 183 | } |
||
| 184 | foreach ($value as $key => $valueElement) { |
||
| 185 | if (!isset($originalData[$key]) |
||
| 186 | || $this->isChanged($valueElement, $originalData[$key], $valueFieldMapping)) { |
||
| 187 | return true; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | return false; |
||
| 191 | } |
||
| 192 | |||
| 193 | // EmbedOne case, or one instance of and EmbedMany |
||
| 194 | if ($this->metadataResolver->canMapDocument($originalData) |
||
| 195 | && get_class($value) !== $this->metadataResolver->getDocumentType($originalData)) { |
||
| 196 | return true; |
||
| 197 | } |
||
| 198 | |||
| 199 | $class = $this->metadataFactory->getMetadataFor(get_class($value)); |
||
| 200 | foreach ($class->reflFields as $fieldName => $fieldValue) { |
||
| 201 | $fieldMapping = $class->fieldMappings[$fieldName]; |
||
| 202 | $originalDataValue = isset($originalData[$fieldMapping['jsonName']]) |
||
| 203 | ? $originalData[$fieldMapping['jsonName']] |
||
| 204 | : null; |
||
| 205 | |||
| 206 | $currentValue = $class->getFieldValue($value, $fieldMapping['fieldName']); |
||
| 207 | |||
| 208 | if ($originalDataValue === null && $currentValue === null) { |
||
| 209 | continue; |
||
| 210 | } else if ($originalDataValue === null || $currentValue === null) { |
||
| 211 | return true; |
||
| 212 | } |
||
| 213 | |||
| 214 | if (!isset($fieldMapping['embedded'])) { |
||
| 215 | // simple property comparison |
||
| 216 | // TODO this conversion could be avoided if we store the php value in the original data |
||
| 217 | // as with the simple property mapping in UOW. |
||
| 218 | $originalValue = Type::getType($fieldMapping['type']) |
||
| 219 | ->convertToPHPValue($originalDataValue); |
||
| 220 | if ($originalValue != $currentValue) { |
||
| 221 | return true; |
||
| 222 | } |
||
| 223 | } else { |
||
| 224 | |||
| 225 | if ('many' == $fieldMapping['embedded']) { |
||
| 226 | if (count($originalDataValue) != count($currentValue)) { |
||
| 227 | return true; |
||
| 228 | } |
||
| 229 | foreach ($currentValue as $currentKey => $currentElem) { |
||
| 230 | if (!isset($originalDataValue[$currentKey])) { |
||
| 231 | return true; |
||
| 232 | } |
||
| 233 | if ($this->isChanged($currentElem, $originalDataValue[$currentKey], $fieldMapping)) { |
||
| 234 | return true; |
||
| 235 | } |
||
| 236 | } |
||
| 237 | } else { // embedOne |
||
| 238 | if ($this->isChanged($currentValue, $originalDataValue, $fieldMapping)) { |
||
| 239 | return true; |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | } |
||
| 244 | } |
||
| 245 | return false; |
||
| 246 | } |
||
| 247 | } |
||
| 248 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.