| Conditions | 10 |
| Paths | 55 |
| Total Lines | 42 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 71 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
| 72 | { |
||
| 73 | $fieldDescription->setAdmin($admin); |
||
| 74 | |||
| 75 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
| 76 | list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
| 77 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
| 78 | |||
| 79 | // set the default field mapping |
||
| 80 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
| 81 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
| 82 | } |
||
| 83 | |||
| 84 | // set the default association mapping |
||
| 85 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
| 86 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | if (!$fieldDescription->getType()) { |
||
| 91 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
||
| 92 | } |
||
| 93 | |||
| 94 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
| 95 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
| 96 | |||
| 97 | if (!$fieldDescription->getTemplate()) { |
||
| 98 | $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); |
||
| 99 | |||
| 100 | if (!$fieldDescription->getTemplate()) { |
||
| 101 | if ($fieldDescription->describesSingleValuedAssociation()) { |
||
| 102 | $fieldDescription->setTemplate('SonataAdminBundle:CRUD/Association:show_single.html.twig'); |
||
| 103 | } elseif ($fieldDescription->describesCollectionValuedAssociation()) { |
||
| 104 | $fieldDescription->setTemplate('SonataAdminBundle:CRUD/Association:show_collection.html.twig'); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($fieldDescription->describesAssociation()) { |
||
| 110 | $admin->attachAdminClass($fieldDescription); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 128 |