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