| Conditions | 11 |
| Paths | 1 |
| Total Lines | 77 |
| Code Lines | 52 |
| 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 |
||
| 63 | public function buildForm(FormBuilderInterface $builder, array $options): void |
||
| 64 | { |
||
| 65 | /** @var StructuralDBElement $entity */ |
||
| 66 | $entity = $options['data']; |
||
| 67 | $is_new = null === $entity->getID(); |
||
| 68 | |||
| 69 | $builder |
||
| 70 | ->add('name', TextType::class, [ |
||
| 71 | 'empty_data' => '', |
||
| 72 | 'label' => 'name.label', |
||
| 73 | 'attr' => [ |
||
| 74 | 'placeholder' => 'part.name.placeholder', |
||
| 75 | ], |
||
| 76 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
|
|
|||
| 77 | ]) |
||
| 78 | |||
| 79 | ->add('parent', StructuralEntityType::class, [ |
||
| 80 | 'class' => get_class($entity), |
||
| 81 | 'required' => false, |
||
| 82 | 'label' => 'parent.label', |
||
| 83 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'move', $entity), |
||
| 84 | ]) |
||
| 85 | |||
| 86 | ->add('not_selectable', CheckboxType::class, [ |
||
| 87 | 'required' => false, |
||
| 88 | 'label' => 'entity.edit.not_selectable', |
||
| 89 | 'help' => 'entity.edit.not_selectable.help', |
||
| 90 | 'label_attr' => [ |
||
| 91 | 'class' => 'checkbox-custom', |
||
| 92 | ], |
||
| 93 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
| 94 | ]) |
||
| 95 | |||
| 96 | ->add('comment', CKEditorType::class, [ |
||
| 97 | 'required' => false, |
||
| 98 | 'empty_data' => '', |
||
| 99 | 'label' => 'comment.label', |
||
| 100 | 'attr' => [ |
||
| 101 | 'rows' => 4, |
||
| 102 | ], |
||
| 103 | 'help' => 'bbcode.hint', |
||
| 104 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
| 105 | ]); |
||
| 106 | |||
| 107 | $this->additionalFormElements($builder, $options, $entity); |
||
| 108 | |||
| 109 | //Attachment section |
||
| 110 | $builder->add('attachments', CollectionType::class, [ |
||
| 111 | 'entry_type' => AttachmentFormType::class, |
||
| 112 | 'allow_add' => true, |
||
| 113 | 'allow_delete' => true, |
||
| 114 | 'label' => false, |
||
| 115 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
| 116 | 'entry_options' => [ |
||
| 117 | 'data_class' => $options['attachment_class'], |
||
| 118 | ], |
||
| 119 | 'by_reference' => false, |
||
| 120 | ]); |
||
| 121 | |||
| 122 | $builder->add('master_picture_attachment', MasterPictureAttachmentType::class, [ |
||
| 123 | 'required' => false, |
||
| 124 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
| 125 | 'label' => 'part.edit.master_attachment', |
||
| 126 | 'entity' => $entity, |
||
| 127 | ]); |
||
| 128 | |||
| 129 | //Buttons |
||
| 130 | $builder->add('save', SubmitType::class, [ |
||
| 131 | 'label' => $is_new ? 'entity.create' : 'entity.edit.save', |
||
| 132 | 'attr' => [ |
||
| 133 | 'class' => $is_new ? 'btn-success' : '', |
||
| 134 | ], |
||
| 135 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
| 136 | ]) |
||
| 137 | ->add('reset', ResetType::class, [ |
||
| 138 | 'label' => 'entity.edit.reset', |
||
| 139 | 'disabled' => ! $this->security->isGranted($is_new ? 'create' : 'edit', $entity), |
||
| 140 | ]); |
||
| 148 |