Conditions | 15 |
Paths | 180 |
Total Lines | 56 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 |
||
72 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
73 | { |
||
74 | $fieldDescription->setAdmin($admin); |
||
75 | |||
76 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
77 | list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
78 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
79 | |||
80 | // set the default field mapping |
||
81 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
82 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
83 | } |
||
84 | |||
85 | // set the default association mapping |
||
86 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
87 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | if (!$fieldDescription->getType()) { |
||
92 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
||
93 | } |
||
94 | |||
95 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
96 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
97 | |||
98 | if (!$fieldDescription->getTemplate()) { |
||
99 | $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); |
||
100 | |||
101 | if (!$fieldDescription->getTemplate()) { |
||
102 | switch ($fieldDescription->getMappingType()) { |
||
103 | case ClassMetadataInfo::MANY_TO_ONE: |
||
104 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_one.html.twig'); |
||
105 | break; |
||
106 | case ClassMetadataInfo::ONE_TO_ONE: |
||
107 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_one.html.twig'); |
||
108 | break; |
||
109 | case ClassMetadataInfo::ONE_TO_MANY: |
||
110 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_many.html.twig'); |
||
111 | break; |
||
112 | case ClassMetadataInfo::MANY_TO_MANY: |
||
113 | $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_many.html.twig'); |
||
114 | break; |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | |||
119 | switch ($fieldDescription->getMappingType()) { |
||
120 | case ClassMetadataInfo::MANY_TO_ONE: |
||
121 | case ClassMetadataInfo::ONE_TO_ONE: |
||
122 | case ClassMetadataInfo::ONE_TO_MANY: |
||
123 | case ClassMetadataInfo::MANY_TO_MANY: |
||
124 | $admin->attachAdminClass($fieldDescription); |
||
125 | break; |
||
126 | } |
||
127 | } |
||
128 | |||
143 |