Conditions | 10 |
Paths | 80 |
Total Lines | 45 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
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 |
||
91 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
92 | { |
||
93 | $fieldDescription->setAdmin($admin); |
||
94 | |||
95 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
96 | $metadata = $admin->getModelManager()->getMetadata($admin->getClass()); |
||
97 | |||
98 | // set the default field mapping |
||
99 | if (isset($metadata->fieldMappings[$fieldDescription->getName()])) { |
||
100 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$fieldDescription->getName()]); |
||
101 | } |
||
102 | |||
103 | // set the default association mapping |
||
104 | if (isset($metadata->associationMappings[$fieldDescription->getName()])) { |
||
105 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$fieldDescription->getName()]); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | if (!$fieldDescription->getType()) { |
||
110 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin))); |
||
111 | } |
||
112 | |||
113 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
114 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
115 | |||
116 | if (!$fieldDescription->getTemplate()) { |
||
117 | |||
118 | $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); |
||
119 | |||
120 | if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_ONE) { |
||
121 | $fieldDescription->setTemplate('SonataDoctrinePhpcrAdminBundle:CRUD:show_phpcr_many_to_one.html.twig'); |
||
122 | } |
||
123 | |||
124 | if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_MANY) { |
||
125 | $fieldDescription->setTemplate('SonataDoctrinePhpcrAdminBundle:CRUD:show_phpcr_many_to_many.html.twig'); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | switch($fieldDescription->getMappingType()) { |
||
130 | case ClassMetadata::MANY_TO_ONE: |
||
131 | case ClassMetadata::MANY_TO_MANY: |
||
132 | $admin->attachAdminClass($fieldDescription); |
||
133 | break; |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 |