Conditions | 17 |
Paths | 23 |
Total Lines | 62 |
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 |
||
118 | public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) |
||
119 | { |
||
120 | $options = []; |
||
121 | $options['sonata_field_description'] = $fieldDescription; |
||
122 | |||
123 | switch ($type) { |
||
124 | case TreeModelType::class: |
||
125 | case 'doctrine_phpcr_odm_tree': |
||
126 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
127 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
128 | |||
129 | break; |
||
130 | case ModelType::class: |
||
131 | case 'sonata_type_model': |
||
132 | case ModelTypeList::class: |
||
133 | case 'sonata_type_model_list': |
||
134 | if ('child' !== $fieldDescription->getMappingType() && !$fieldDescription->getTargetEntity()) { |
||
|
|||
135 | throw new \LogicException(sprintf( |
||
136 | 'The field "%s" in class "%s" does not have a target model defined. Please specify the "targetDocument" attribute in the mapping for this class.', |
||
137 | $fieldDescription->getName(), |
||
138 | $fieldDescription->getAdmin()->getClass() |
||
139 | )); |
||
140 | } |
||
141 | |||
142 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
143 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
144 | |||
145 | break; |
||
146 | case AdminType::class: |
||
147 | case 'sonata_type_admin': |
||
148 | if (!$fieldDescription->getAssociationAdmin()) { |
||
149 | throw $this->getAssociationAdminException($fieldDescription); |
||
150 | } |
||
151 | |||
152 | $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass(); |
||
153 | $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin')); |
||
154 | |||
155 | break; |
||
156 | case DeprecatedCollectionType::class: |
||
157 | case 'sonata_type_collection_legacy': |
||
158 | /* |
||
159 | * NEXT_MAJOR: Remove 'Sonata\CoreBundle\Form\Type\CollectionType' and 'sonata_type_collection_legacy' |
||
160 | * cases when replace SonataCoreBundle by SonataFormExtension |
||
161 | */ |
||
162 | case CollectionType::class: |
||
163 | case 'sonata_type_collection': |
||
164 | if (!$fieldDescription->getAssociationAdmin()) { |
||
165 | throw $this->getAssociationAdminException($fieldDescription); |
||
166 | } |
||
167 | |||
168 | $options['type'] = AdminType::class; |
||
169 | $options['modifiable'] = true; |
||
170 | $options['type_options'] = [ |
||
171 | 'sonata_field_description' => $fieldDescription, |
||
172 | 'data_class' => $fieldDescription->getAssociationAdmin()->getClass(), |
||
173 | ]; |
||
174 | |||
175 | break; |
||
176 | } |
||
177 | |||
178 | return $options; |
||
179 | } |
||
180 | |||
199 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: