| Conditions | 12 |
| Paths | 2 |
| Total Lines | 42 |
| 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 |
||
| 35 | public function resolveJsonField(ClassMetadata $class, DocumentManager $dm, $documentState, $jsonName, $originalData) |
||
| 36 | { |
||
| 37 | $uow = $dm->getUnitOfWork(); |
||
| 38 | $couchClient = $dm->getCouchDBClient(); |
||
| 39 | |||
| 40 | if ($jsonName == 'doctrine_metadata' && isset($originalData['doctrine_metadata']['associations'])) { |
||
| 41 | foreach ($originalData['doctrine_metadata']['associations'] AS $assocName) { |
||
| 42 | $assocValue = $originalData[$assocName]; |
||
| 43 | if (isset($class->associationsMappings[$assocName])) { |
||
| 44 | if ($class->associationsMappings[$assocName]['type'] & ClassMetadata::TO_ONE) { |
||
| 45 | if ($assocValue) { |
||
| 46 | if ($class->associationsMappings[$assocName]['targetDocument'] && |
||
| 47 | ! $dm->getClassMetadata($class->associationsMappings[$assocName]['targetDocument'])->inInheritanceHierachy) { |
||
| 48 | |||
| 49 | $assocValue = $dm->getReference($class->associationsMappings[$assocName]['targetDocument'], $assocValue); |
||
| 50 | } else { |
||
| 51 | $response = $couchClient->findDocument($assocValue); |
||
| 52 | |||
| 53 | if ($response->status == 404) { |
||
| 54 | $assocValue = null; |
||
| 55 | } else { |
||
| 56 | $hints = array(); |
||
| 57 | $assocValue = $uow->createDocument(null, $response->body, $hints); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | $documentState[$class->associationsMappings[$assocName]['fieldName']] = $assocValue; |
||
| 62 | } else if ($class->associationsMappings[$assocName]['type'] & ClassMetadata::MANY_TO_MANY) { |
||
| 63 | if ($class->associationsMappings[$assocName]['isOwning']) { |
||
| 64 | $documentState[$class->associationsMappings[$assocName]['fieldName']] = new PersistentIdsCollection( |
||
| 65 | new ArrayCollection(), |
||
| 66 | $class->associationsMappings[$assocName]['targetDocument'], |
||
| 67 | $dm, |
||
| 68 | $assocValue |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | return $documentState; |
||
| 76 | } |
||
| 77 | |||
| 90 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.