Conditions | 18 |
Paths | 8 |
Total Lines | 119 |
Code Lines | 80 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
85 | public function buildForm(FormBuilderInterface $builder, array $options): void |
||
86 | { |
||
87 | /** @var AbstractStructuralDBElement $entity */ |
||
88 | $entity = $options['data']; |
||
89 | $is_new = null === $entity->getID(); |
||
90 | |||
91 | $builder |
||
92 | ->add('name', TextType::class, [ |
||
93 | 'empty_data' => '', |
||
94 | 'label' => 'name.label', |
||
95 | 'attr' => [ |
||
96 | 'placeholder' => 'part.name.placeholder', |
||
97 | ], |
||
98 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
99 | ]); |
||
100 | |||
101 | if ($entity instanceof AbstractStructuralDBElement) { |
||
|
|||
102 | $builder->add( |
||
103 | 'parent', |
||
104 | StructuralEntityType::class, |
||
105 | [ |
||
106 | 'class' => get_class($entity), |
||
107 | 'required' => false, |
||
108 | 'label' => 'parent.label', |
||
109 | 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'move', $entity), |
||
110 | ] |
||
111 | ) |
||
112 | ->add( |
||
113 | 'not_selectable', |
||
114 | CheckboxType::class, |
||
115 | [ |
||
116 | 'required' => false, |
||
117 | 'label' => 'entity.edit.not_selectable', |
||
118 | 'help' => 'entity.edit.not_selectable.help', |
||
119 | 'label_attr' => [ |
||
120 | 'class' => 'checkbox-custom', |
||
121 | ], |
||
122 | 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
123 | ] |
||
124 | ); |
||
125 | } |
||
126 | if ($entity instanceof AbstractStructuralDBElement || $entity instanceof LabelProfile) { |
||
127 | $builder->add( |
||
128 | 'comment', |
||
129 | CKEditorType::class, |
||
130 | [ |
||
131 | 'required' => false, |
||
132 | 'empty_data' => '', |
||
133 | 'label' => 'comment.label', |
||
134 | 'attr' => [ |
||
135 | 'rows' => 4, |
||
136 | ], |
||
137 | 'help' => 'bbcode.hint', |
||
138 | 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
139 | ] |
||
140 | ); |
||
141 | } |
||
142 | |||
143 | $this->additionalFormElements($builder, $options, $entity); |
||
144 | |||
145 | //Attachment section |
||
146 | $builder->add('attachments', CollectionType::class, [ |
||
147 | 'entry_type' => AttachmentFormType::class, |
||
148 | 'allow_add' => true, |
||
149 | 'allow_delete' => true, |
||
150 | 'label' => false, |
||
151 | 'reindex_enable' => true, |
||
152 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
153 | 'entry_options' => [ |
||
154 | 'data_class' => $options['attachment_class'], |
||
155 | ], |
||
156 | 'by_reference' => false, |
||
157 | ]); |
||
158 | |||
159 | $builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [ |
||
160 | 'required' => false, |
||
161 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
162 | 'label' => 'part.edit.master_attachment', |
||
163 | 'entity' => $entity, |
||
164 | ]); |
||
165 | |||
166 | $builder->add('log_comment', TextType::class, [ |
||
167 | 'label' => 'edit.log_comment', |
||
168 | 'mapped' => false, |
||
169 | 'required' => false, |
||
170 | 'empty_data' => null, |
||
171 | ]); |
||
172 | |||
173 | if ($entity instanceof AbstractStructuralDBElement) { |
||
174 | $builder->add( |
||
175 | 'parameters', |
||
176 | CollectionType::class, |
||
177 | [ |
||
178 | 'entry_type' => ParameterType::class, |
||
179 | 'allow_add' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
180 | 'allow_delete' => $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
181 | 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
182 | 'reindex_enable' => true, |
||
183 | 'label' => false, |
||
184 | 'by_reference' => false, |
||
185 | 'prototype_data' => new $options['parameter_class'](), |
||
186 | 'entry_options' => [ |
||
187 | 'data_class' => $options['parameter_class'], |
||
188 | ], |
||
189 | ] |
||
190 | ); |
||
191 | } |
||
192 | |||
193 | //Buttons |
||
194 | $builder->add('save', SubmitType::class, [ |
||
195 | 'label' => $is_new ? 'entity.create' : 'entity.edit.save', |
||
196 | 'attr' => [ |
||
197 | 'class' => $is_new ? 'btn-success' : '', |
||
198 | ], |
||
199 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
200 | ]) |
||
201 | ->add('reset', ResetType::class, [ |
||
202 | 'label' => 'entity.edit.reset', |
||
203 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
204 | ]); |
||
212 |