| Conditions | 9 |
| Paths | 22 |
| Total Lines | 63 |
| Code Lines | 36 |
| 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 |
||
| 66 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
| 67 | { |
||
| 68 | // set default values |
||
| 69 | $fieldDescription->setAdmin($admin); |
||
| 70 | |||
| 71 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
| 72 | list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager() |
||
| 73 | ->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
| 74 | |||
| 75 | // set the default field mapping |
||
| 76 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
| 77 | $fieldDescription->setOption( |
||
| 78 | 'field_mapping', |
||
| 79 | $fieldDescription->getOption( |
||
| 80 | 'field_mapping', |
||
| 81 | $fieldMapping = $metadata->fieldMappings[$lastPropertyName] |
||
| 82 | ) |
||
| 83 | ); |
||
| 84 | |||
| 85 | if ('string' == $fieldMapping['type']) { |
||
| 86 | $fieldDescription->setOption('global_search', $fieldDescription->getOption('global_search', true)); // always search on string field only |
||
| 87 | } |
||
| 88 | |||
| 89 | if (!empty($embeddedClasses = $metadata->embeddedClasses) |
||
| 90 | && isset($fieldMapping['declaredField']) |
||
| 91 | && array_key_exists($fieldMapping['declaredField'], $embeddedClasses) |
||
| 92 | ) { |
||
| 93 | $fieldDescription->setOption( |
||
| 94 | 'field_name', |
||
| 95 | $fieldMapping['fieldName'] |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | // set the default association mapping |
||
| 101 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
| 102 | $fieldDescription->setOption( |
||
| 103 | 'association_mapping', |
||
| 104 | $fieldDescription->getOption( |
||
| 105 | 'association_mapping', |
||
| 106 | $metadata->associationMappings[$lastPropertyName] |
||
| 107 | ) |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | |||
| 111 | $fieldDescription->setOption( |
||
| 112 | 'parent_association_mappings', |
||
| 113 | $fieldDescription->getOption('parent_association_mappings', $parentAssociationMappings) |
||
| 114 | ); |
||
| 115 | } |
||
| 116 | |||
| 117 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
| 118 | $fieldDescription->setOption('name', $fieldDescription->getOption('name', $fieldDescription->getName())); |
||
| 119 | |||
| 120 | if (in_array($fieldDescription->getMappingType(), [ |
||
| 121 | ClassMetadata::ONE_TO_MANY, |
||
| 122 | ClassMetadata::MANY_TO_MANY, |
||
| 123 | ClassMetadata::MANY_TO_ONE, |
||
| 124 | ClassMetadata::ONE_TO_ONE, |
||
| 125 | ])) { |
||
| 126 | $admin->attachAdminClass($fieldDescription); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 215 |