| Conditions | 14 |
| Paths | 490 |
| Total Lines | 63 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 2 | 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 |
||
| 74 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
| 75 | { |
||
| 76 | if ($fieldDescription->getName() == '_action') { |
||
| 77 | $this->buildActionFieldDescription($fieldDescription); |
||
| 78 | } |
||
| 79 | |||
| 80 | $fieldDescription->setAdmin($admin); |
||
| 81 | |||
| 82 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
| 83 | list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
| 84 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
| 85 | |||
| 86 | // set the default field mapping |
||
| 87 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
| 88 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
| 89 | if ($fieldDescription->getOption('sortable') !== false) { |
||
| 90 | $fieldDescription->setOption('sortable', $fieldDescription->getOption('sortable', true)); |
||
| 91 | $fieldDescription->setOption('sort_parent_association_mappings', $fieldDescription->getOption('sort_parent_association_mappings', $fieldDescription->getParentAssociationMappings())); |
||
| 92 | $fieldDescription->setOption('sort_field_mapping', $fieldDescription->getOption('sort_field_mapping', $fieldDescription->getFieldMapping())); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | // set the default association mapping |
||
| 97 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
| 98 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
| 99 | } |
||
| 100 | |||
| 101 | $fieldDescription->setOption('_sort_order', $fieldDescription->getOption('_sort_order', 'ASC')); |
||
| 102 | } |
||
| 103 | |||
| 104 | if (!$fieldDescription->getType()) { |
||
| 105 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
||
| 106 | } |
||
| 107 | |||
| 108 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
| 109 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
| 110 | |||
| 111 | if (!$fieldDescription->getTemplate()) { |
||
| 112 | if ($fieldDescription->getType() == 'id') { |
||
| 113 | $fieldDescription->setType('string'); |
||
| 114 | } |
||
| 115 | |||
| 116 | if ($fieldDescription->getType() == 'int') { |
||
| 117 | $fieldDescription->setType('integer'); |
||
| 118 | } |
||
| 119 | |||
| 120 | $template = $this->getTemplate($fieldDescription->getType()); |
||
| 121 | |||
| 122 | if ($template === null) { |
||
| 123 | if ($fieldDescription->getMappingType() == ClassMetadataInfo::ONE) { |
||
| 124 | $template = 'SonataDoctrineMongoDBAdminBundle:CRUD:list_mongo_one.html.twig'; |
||
| 125 | } elseif ($fieldDescription->getMappingType() == ClassMetadataInfo::MANY) { |
||
| 126 | $template = 'SonataDoctrineMongoDBAdminBundle:CRUD:list_mongo_many.html.twig'; |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | $fieldDescription->setTemplate($template); |
||
| 131 | } |
||
| 132 | |||
| 133 | if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE, ClassMetadataInfo::MANY))) { |
||
| 134 | $admin->attachAdminClass($fieldDescription); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 189 |