| Conditions | 14 |
| Paths | 19 |
| Total Lines | 57 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 105 | public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) |
||
| 106 | { |
||
| 107 | $options = array(); |
||
| 108 | $options['sonata_field_description'] = $fieldDescription; |
||
| 109 | |||
| 110 | switch ($type) { |
||
| 111 | case 'Sonata\DoctrinePHPCRAdminBundle\Form\Type\TreeModelType': |
||
| 112 | case 'doctrine_phpcr_odm_tree': |
||
| 113 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
| 114 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
| 115 | |||
| 116 | break; |
||
| 117 | case 'Sonata\AdminBundle\Form\Type\Modeltype': |
||
| 118 | case 'sonata_type_model': |
||
| 119 | case 'Sonata\AdminBundle\Form\Type\ModelTypeList': |
||
| 120 | case 'sonata_type_model_list': |
||
| 121 | if (!$fieldDescription->getTargetEntity()) { |
||
|
|
|||
| 122 | throw new \LogicException(sprintf( |
||
| 123 | 'The field "%s" in class "%s" does not have a target model defined. ' . |
||
| 124 | 'Please specify the "targetDocument" attribute in the mapping for this class.', |
||
| 125 | $fieldDescription->getName(), |
||
| 126 | $fieldDescription->getAdmin()->getClass() |
||
| 127 | )); |
||
| 128 | } |
||
| 129 | |||
| 130 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
| 131 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
| 132 | |||
| 133 | break; |
||
| 134 | case 'Sonata\AdminBundle\Form\Type\AdminType': |
||
| 135 | case 'sonata_type_admin': |
||
| 136 | if (!$fieldDescription->getAssociationAdmin()) { |
||
| 137 | throw $this->getAssociationAdminException($fieldDescription); |
||
| 138 | } |
||
| 139 | |||
| 140 | $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass(); |
||
| 141 | $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin')); |
||
| 142 | |||
| 143 | break; |
||
| 144 | case 'Sonata\CoreBundle\Form\Type\CollectionType': |
||
| 145 | case 'sonata_type_collection': |
||
| 146 | if (!$fieldDescription->getAssociationAdmin()) { |
||
| 147 | throw $this->getAssociationAdminException($fieldDescription); |
||
| 148 | } |
||
| 149 | |||
| 150 | $options['type'] = 'sonata_type_admin'; |
||
| 151 | $options['modifiable'] = true; |
||
| 152 | $options['type_options'] = array( |
||
| 153 | 'sonata_field_description' => $fieldDescription, |
||
| 154 | 'data_class' => $fieldDescription->getAssociationAdmin()->getClass() |
||
| 155 | ); |
||
| 156 | |||
| 157 | break; |
||
| 158 | } |
||
| 159 | |||
| 160 | return $options; |
||
| 161 | } |
||
| 162 | |||
| 183 |
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: