| Conditions | 15 |
| Paths | 19 |
| Total Lines | 56 |
| 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 |
||
| 111 | public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) |
||
| 112 | { |
||
| 113 | $options = []; |
||
| 114 | $options['sonata_field_description'] = $fieldDescription; |
||
| 115 | |||
| 116 | switch ($type) { |
||
| 117 | case 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType': |
||
| 118 | case 'doctrine_phpcr_odm_tree': |
||
| 119 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
| 120 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
| 121 | |||
| 122 | break; |
||
| 123 | case 'Sonata\AdminBundle\Form\Type\ModelType': |
||
| 124 | case 'sonata_type_model': |
||
| 125 | case 'Sonata\AdminBundle\Form\Type\ModelTypeList': |
||
| 126 | case 'sonata_type_model_list': |
||
| 127 | if ('child' !== $fieldDescription->getMappingType() && !$fieldDescription->getTargetEntity()) { |
||
|
|
|||
| 128 | throw new \LogicException(sprintf( |
||
| 129 | 'The field "%s" in class "%s" does not have a target model defined. Please specify the "targetDocument" attribute in the mapping for this class.', |
||
| 130 | $fieldDescription->getName(), |
||
| 131 | $fieldDescription->getAdmin()->getClass() |
||
| 132 | )); |
||
| 133 | } |
||
| 134 | |||
| 135 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
| 136 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
| 137 | |||
| 138 | break; |
||
| 139 | case 'Sonata\AdminBundle\Form\Type\AdminType': |
||
| 140 | case 'sonata_type_admin': |
||
| 141 | if (!$fieldDescription->getAssociationAdmin()) { |
||
| 142 | throw $this->getAssociationAdminException($fieldDescription); |
||
| 143 | } |
||
| 144 | |||
| 145 | $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass(); |
||
| 146 | $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin')); |
||
| 147 | |||
| 148 | break; |
||
| 149 | case 'Sonata\CoreBundle\Form\Type\CollectionType': |
||
| 150 | case 'sonata_type_collection': |
||
| 151 | if (!$fieldDescription->getAssociationAdmin()) { |
||
| 152 | throw $this->getAssociationAdminException($fieldDescription); |
||
| 153 | } |
||
| 154 | |||
| 155 | $options['type'] = 'Sonata\AdminBundle\Form\Type\AdminType'; |
||
| 156 | $options['modifiable'] = true; |
||
| 157 | $options['type_options'] = [ |
||
| 158 | 'sonata_field_description' => $fieldDescription, |
||
| 159 | 'data_class' => $fieldDescription->getAssociationAdmin()->getClass(), |
||
| 160 | ]; |
||
| 161 | |||
| 162 | break; |
||
| 163 | } |
||
| 164 | |||
| 165 | return $options; |
||
| 166 | } |
||
| 167 | |||
| 188 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: