| Conditions | 14 |
| Paths | 210 |
| Total Lines | 62 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 80 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
| 81 | { |
||
| 82 | if ($fieldDescription->getName() == '_action') { |
||
| 83 | $this->buildActionFieldDescription($fieldDescription); |
||
| 84 | } |
||
| 85 | |||
| 86 | $fieldDescription->setAdmin($admin); |
||
| 87 | |||
| 88 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
| 89 | list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
| 90 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
| 91 | |||
| 92 | // set the default field mapping |
||
| 93 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
| 94 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
| 95 | if ($fieldDescription->getOption('sortable') !== false) { |
||
| 96 | $fieldDescription->setOption('sortable', $fieldDescription->getOption('sortable', true)); |
||
| 97 | $fieldDescription->setOption('sort_parent_association_mappings', $fieldDescription->getOption('sort_parent_association_mappings', $fieldDescription->getParentAssociationMappings())); |
||
| 98 | $fieldDescription->setOption('sort_field_mapping', $fieldDescription->getOption('sort_field_mapping', $fieldDescription->getFieldMapping())); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | // set the default association mapping |
||
| 103 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
| 104 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
| 105 | } |
||
| 106 | |||
| 107 | $fieldDescription->setOption('_sort_order', $fieldDescription->getOption('_sort_order', 'ASC')); |
||
| 108 | } |
||
| 109 | |||
| 110 | if (!$fieldDescription->getType()) { |
||
| 111 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
||
| 112 | } |
||
| 113 | |||
| 114 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
| 115 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
| 116 | |||
| 117 | if (!$fieldDescription->getTemplate()) { |
||
| 118 | $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); |
||
| 119 | |||
| 120 | if (!$fieldDescription->getTemplate()) { |
||
| 121 | switch ($fieldDescription->getMappingType()) { |
||
| 122 | case ClassMetadataInfo::MANY_TO_ONE: |
||
| 123 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:list_orm_many_to_one.html.twig'); |
||
| 124 | break; |
||
| 125 | case ClassMetadataInfo::ONE_TO_ONE: |
||
| 126 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:list_orm_one_to_one.html.twig'); |
||
| 127 | break; |
||
| 128 | case ClassMetadataInfo::ONE_TO_MANY: |
||
| 129 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:list_orm_one_to_many.html.twig'); |
||
| 130 | break; |
||
| 131 | case ClassMetadataInfo::MANY_TO_MANY: |
||
| 132 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:list_orm_many_to_many.html.twig'); |
||
| 133 | break; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY))) { |
||
| 139 | $admin->attachAdminClass($fieldDescription); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 194 |