| Conditions | 11 |
| Paths | 8 |
| Total Lines | 47 |
| Code Lines | 29 |
| 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 |
||
| 87 | public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) |
||
| 88 | { |
||
| 89 | $options = array(); |
||
| 90 | $options['sonata_field_description'] = $fieldDescription; |
||
| 91 | |||
| 92 | // NEXT_MAJOR: Check only against FQCNs when dropping support for Symfony <2.8 |
||
| 93 | if ($this->checkFormType($type, array( |
||
| 94 | 'sonata_type_model', |
||
| 95 | 'sonata_type_model_list', |
||
| 96 | )) || $this->checkFormClass($type, array( |
||
| 97 | 'Sonata\AdminBundle\Form\Type\ModelType', |
||
| 98 | 'Sonata\AdminBundle\Form\Type\ModelListType', |
||
| 99 | ))) { |
||
| 100 | if ($fieldDescription->getOption('edit') == 'list') { |
||
| 101 | throw new \LogicException('The ``sonata_type_model`` type does not accept an ``edit`` option anymore, please review the UPGRADE-2.1.md file from the SonataAdminBundle'); |
||
| 102 | } |
||
| 103 | |||
| 104 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
| 105 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
| 106 | // NEXT_MAJOR: Check only against FQCNs when dropping support for Symfony <2.8 |
||
| 107 | } elseif ($this->checkFormType($type, array('sonata_type_admin')) || $this->checkFormClass($type, array('Sonata\AdminBundle\Form\Type\AdminType'))) { |
||
| 108 | if (!$fieldDescription->getAssociationAdmin()) { |
||
| 109 | throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity())); |
||
| 110 | } |
||
| 111 | |||
| 112 | $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass(); |
||
| 113 | $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin')); |
||
| 114 | // NEXT_MAJOR: Check only against FQCNs when dropping support for Symfony <2.8 |
||
| 115 | } elseif ($this->checkFormType($type, array('sonata_type_collection')) || $this->checkFormClass($type, array('Sonata\CoreBundle\Form\Type\CollectionType'))) { |
||
| 116 | if (!$fieldDescription->getAssociationAdmin()) { |
||
| 117 | throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity())); |
||
| 118 | } |
||
| 119 | |||
| 120 | // NEXT_MAJOR: Use only FQCN when dropping support for Symfony <2.8 |
||
| 121 | $options['type'] = 'sonata_type_collection' === $type ? |
||
| 122 | 'sonata_type_admin' : |
||
| 123 | 'Sonata\AdminBundle\Form\Type\AdminType' |
||
| 124 | ; |
||
| 125 | $options['modifiable'] = true; |
||
| 126 | $options['type_options'] = array( |
||
| 127 | 'sonata_field_description' => $fieldDescription, |
||
| 128 | 'data_class' => $fieldDescription->getAssociationAdmin()->getClass(), |
||
| 129 | ); |
||
| 130 | } |
||
| 131 | |||
| 132 | return $options; |
||
| 133 | } |
||
| 134 | |||
| 161 |