Conditions | 10 |
Paths | 10 |
Total Lines | 79 |
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 |
||
95 | public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription) |
||
96 | { |
||
97 | $options = []; |
||
98 | $options['sonata_field_description'] = $fieldDescription; |
||
99 | |||
100 | if ($this->checkFormClass($type, [ |
||
101 | ModelType::class, |
||
102 | ModelTypeList::class, |
||
103 | ModelListType::class, |
||
104 | ModelHiddenType::class, |
||
105 | ModelAutocompleteType::class, |
||
106 | ])) { |
||
107 | if ('list' === $fieldDescription->getOption('edit')) { |
||
108 | throw new \LogicException( |
||
109 | 'The ``Sonata\AdminBundle\Form\Type\ModelType`` type does not accept an ``edit`` option anymore,' |
||
110 | .' please review the UPGRADE-2.1.md file from the SonataAdminBundle' |
||
111 | ); |
||
112 | } |
||
113 | |||
114 | $options['class'] = $fieldDescription->getTargetEntity(); |
||
|
|||
115 | $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager(); |
||
116 | |||
117 | if ($this->checkFormClass($type, [ModelAutocompleteType::class])) { |
||
118 | if (!$fieldDescription->getAssociationAdmin()) { |
||
119 | throw new \RuntimeException(sprintf( |
||
120 | 'The current field `%s` is not linked to an admin.' |
||
121 | .' Please create one for the target entity: `%s`', |
||
122 | $fieldDescription->getName(), |
||
123 | $fieldDescription->getTargetEntity() |
||
124 | )); |
||
125 | } |
||
126 | } |
||
127 | } elseif ($this->checkFormClass($type, [AdminType::class])) { |
||
128 | if (!$fieldDescription->getAssociationAdmin()) { |
||
129 | throw new \RuntimeException(sprintf( |
||
130 | 'The current field `%s` is not linked to an admin.' |
||
131 | .' Please create one for the target entity : `%s`', |
||
132 | $fieldDescription->getName(), |
||
133 | $fieldDescription->getTargetEntity() |
||
134 | )); |
||
135 | } |
||
136 | |||
137 | if (!\in_array($fieldDescription->getMappingType(), [ClassMetadata::ONE, ClassMetadata::MANY], true)) { |
||
138 | throw new \RuntimeException(sprintf( |
||
139 | 'You are trying to add `sonata_type_admin` field `%s` which is not One-To-One or Many-To-One.' |
||
140 | .' Maybe you want `sonata_type_collection` instead?', |
||
141 | $fieldDescription->getName() |
||
142 | )); |
||
143 | } |
||
144 | |||
145 | // set sensitive default value to have a component working fine out of the box |
||
146 | $options['btn_add'] = false; |
||
147 | $options['delete'] = false; |
||
148 | |||
149 | $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass(); |
||
150 | $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin')); |
||
151 | } elseif ($this->checkFormClass($type, [ |
||
152 | CollectionType::class, |
||
153 | DeprecatedCollectionType::class, |
||
154 | ])) { |
||
155 | if (!$fieldDescription->getAssociationAdmin()) { |
||
156 | throw new \RuntimeException(sprintf( |
||
157 | 'The current field `%s` is not linked to an admin.' |
||
158 | .' Please create one for the target entity : `%s`', |
||
159 | $fieldDescription->getName(), |
||
160 | $fieldDescription->getTargetEntity() |
||
161 | )); |
||
162 | } |
||
163 | |||
164 | $options['type'] = AdminType::class; |
||
165 | $options['modifiable'] = true; |
||
166 | $options['type_options'] = [ |
||
167 | 'sonata_field_description' => $fieldDescription, |
||
168 | 'data_class' => $fieldDescription->getAssociationAdmin()->getClass(), |
||
169 | ]; |
||
170 | } |
||
171 | |||
172 | return $options; |
||
173 | } |
||
174 | |||
188 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.