| Conditions | 12 |
| Paths | 175 |
| Total Lines | 52 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 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 |
||
| 76 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
| 77 | { |
||
| 78 | $fieldDescription->setAdmin($admin); |
||
| 79 | |||
| 80 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
| 81 | list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
| 82 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
| 83 | |||
| 84 | // set the default field mapping |
||
| 85 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
| 86 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
| 87 | } |
||
| 88 | |||
| 89 | // set the default association mapping |
||
| 90 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
| 91 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | if (!$fieldDescription->getType()) { |
||
| 96 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
||
| 97 | } |
||
| 98 | |||
| 99 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
| 100 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
| 101 | |||
| 102 | if (!$fieldDescription->getTemplate()) { |
||
| 103 | if ($fieldDescription->getType() == 'id') { |
||
| 104 | $fieldDescription->setType('string'); |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($fieldDescription->getType() == 'int') { |
||
| 108 | $fieldDescription->setType('integer'); |
||
| 109 | } |
||
| 110 | |||
| 111 | $template = $this->getTemplate($fieldDescription->getType()); |
||
| 112 | |||
| 113 | if ($template === null) { |
||
| 114 | if ($fieldDescription->getMappingType() == ClassMetadataInfo::ONE) { |
||
| 115 | $template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_one.html.twig'; |
||
| 116 | } elseif ($fieldDescription->getMappingType() == ClassMetadataInfo::MANY) { |
||
| 117 | $template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_many.html.twig'; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | $fieldDescription->setTemplate($template); |
||
| 122 | } |
||
| 123 | |||
| 124 | if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE, ClassMetadataInfo::MANY))) { |
||
| 125 | $admin->attachAdminClass($fieldDescription); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 143 |