Conditions | 15 |
Paths | 180 |
Total Lines | 59 |
Code Lines | 36 |
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 |
||
93 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
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 | } |
||
105 | |||
106 | // set the default association mapping |
||
107 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
108 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | if (!$fieldDescription->getType()) { |
||
113 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
||
114 | } |
||
115 | |||
116 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
117 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
118 | |||
119 | if (!$fieldDescription->getTemplate()) { |
||
120 | |||
121 | $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); |
||
122 | |||
123 | if (!$fieldDescription->getTemplate()) { |
||
124 | |||
125 | switch($fieldDescription->getMappingType()) { |
||
126 | case ClassMetadataInfo::MANY_TO_ONE: |
||
127 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_one.html.twig'); |
||
128 | break; |
||
129 | case ClassMetadataInfo::ONE_TO_ONE: |
||
130 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_one.html.twig'); |
||
131 | break; |
||
132 | case ClassMetadataInfo::ONE_TO_MANY: |
||
133 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_many.html.twig'); |
||
134 | break; |
||
135 | case ClassMetadataInfo::MANY_TO_MANY: |
||
136 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_many.html.twig'); |
||
137 | break; |
||
138 | } |
||
139 | |||
140 | } |
||
141 | } |
||
142 | |||
143 | switch($fieldDescription->getMappingType()) { |
||
144 | case ClassMetadataInfo::MANY_TO_ONE: |
||
145 | case ClassMetadataInfo::ONE_TO_ONE: |
||
146 | case ClassMetadataInfo::ONE_TO_MANY: |
||
147 | case ClassMetadataInfo::MANY_TO_MANY: |
||
148 | $admin->attachAdminClass($fieldDescription); |
||
149 | break; |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 |