| Conditions | 14 |
| Paths | 210 |
| Total Lines | 74 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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( |
||
| 112 | 'Please define a type for field `%s` in `%s`', |
||
| 113 | $fieldDescription->getName(), |
||
| 114 | get_class($admin) |
||
| 115 | )); |
||
| 116 | } |
||
| 117 | |||
| 118 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
| 119 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
| 120 | |||
| 121 | if (!$fieldDescription->getTemplate()) { |
||
| 122 | $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); |
||
| 123 | |||
| 124 | if (!$fieldDescription->getTemplate()) { |
||
| 125 | switch ($fieldDescription->getMappingType()) { |
||
| 126 | case ClassMetadataInfo::MANY_TO_ONE: |
||
| 127 | $fieldDescription->setTemplate( |
||
| 128 | 'SonataDoctrineORMAdminBundle:CRUD:list_orm_many_to_one.html.twig' |
||
| 129 | ); |
||
| 130 | break; |
||
| 131 | case ClassMetadataInfo::ONE_TO_ONE: |
||
| 132 | $fieldDescription->setTemplate( |
||
| 133 | 'SonataDoctrineORMAdminBundle:CRUD:list_orm_one_to_one.html.twig' |
||
| 134 | ); |
||
| 135 | break; |
||
| 136 | case ClassMetadataInfo::ONE_TO_MANY: |
||
| 137 | $fieldDescription->setTemplate( |
||
| 138 | 'SonataDoctrineORMAdminBundle:CRUD:list_orm_one_to_many.html.twig' |
||
| 139 | ); |
||
| 140 | break; |
||
| 141 | case ClassMetadataInfo::MANY_TO_MANY: |
||
| 142 | $fieldDescription->setTemplate( |
||
| 143 | 'SonataDoctrineORMAdminBundle:CRUD:list_orm_many_to_many.html.twig' |
||
| 144 | ); |
||
| 145 | break; |
||
| 146 | } |
||
| 147 | } |
||
| 148 | } |
||
| 149 | |||
| 150 | if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY))) { |
||
| 151 | $admin->attachAdminClass($fieldDescription); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 206 |