| Conditions | 3 |
| Paths | 1 |
| Total Lines | 132 |
| Code Lines | 92 |
| 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 |
||
| 79 | public function buildForm(FormBuilderInterface $builder, array $options) |
||
| 80 | { |
||
| 81 | /** @var StructuralDBElement $entity */ |
||
| 82 | $entity = $options['data']; |
||
| 83 | $is_new = $entity->getID() === null; |
||
| 84 | |||
| 85 | $builder |
||
| 86 | ->add('name', TextType::class, [ |
||
| 87 | 'empty_data' => '', |
||
| 88 | 'label' => $this->trans->trans('user.username.label'), |
||
| 89 | 'attr' => ['placeholder' => $this->trans->trans('user.username.placeholder')], |
||
| 90 | 'disabled' => !$this->security->isGranted('edit_username', $entity), |
||
| 91 | ]) |
||
| 92 | |||
| 93 | ->add('group', StructuralEntityType::class, [ |
||
| 94 | 'class' => Group::class, |
||
| 95 | 'required' => false, |
||
| 96 | 'label' => $this->trans->trans('group.label'), |
||
| 97 | 'disable_not_selectable' => true, |
||
| 98 | 'disabled' => !$this->security->isGranted('change_group', $entity), ]) |
||
| 99 | |||
| 100 | ->add('first_name', TextType::class, [ |
||
| 101 | 'empty_data' => '', |
||
| 102 | 'label' => $this->trans->trans('user.firstName.label'), |
||
| 103 | 'attr' => ['placeholder' => $this->trans->trans('user.firstName.placeholder')], 'required' => false, |
||
| 104 | 'disabled' => !$this->security->isGranted('edit_infos', $entity), |
||
| 105 | ]) |
||
| 106 | |||
| 107 | ->add('last_name', TextType::class, [ |
||
| 108 | 'empty_data' => '', |
||
| 109 | 'label' => $this->trans->trans('user.lastName.label'), |
||
| 110 | 'attr' => ['placeholder' => $this->trans->trans('user.lastName.placeholder')], |
||
| 111 | 'required' => false, |
||
| 112 | 'disabled' => !$this->security->isGranted('edit_infos', $entity), |
||
| 113 | ]) |
||
| 114 | |||
| 115 | ->add('email', TextType::class, [ |
||
| 116 | 'empty_data' => '', |
||
| 117 | 'label' => $this->trans->trans('user.email.label'), |
||
| 118 | 'attr' => ['placeholder' => $this->trans->trans('user.email.placeholder')], |
||
| 119 | 'required' => false, |
||
| 120 | 'disabled' => !$this->security->isGranted('edit_infos', $entity), ]) |
||
| 121 | |||
| 122 | |||
| 123 | ->add('department', TextType::class, [ |
||
| 124 | 'empty_data' => '', |
||
| 125 | 'label' => $this->trans->trans('user.department.label'), |
||
| 126 | 'attr' => ['placeholder' => $this->trans->trans('user.department.placeholder')], |
||
| 127 | 'required' => false, |
||
| 128 | 'disabled' => !$this->security->isGranted('edit_infos', $entity), |
||
| 129 | ]) |
||
| 130 | |||
| 131 | //Config section |
||
| 132 | ->add('language', LanguageType::class, [ |
||
| 133 | 'required' => false, |
||
| 134 | 'attr' => ['class' => 'selectpicker', 'data-live-search' => true], |
||
| 135 | 'placeholder' => $this->trans->trans('user_settings.language.placeholder'), |
||
| 136 | 'label' => $this->trans->trans('user.language_select'), |
||
| 137 | 'preferred_choices' => ['en', 'de'], |
||
| 138 | 'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
||
| 139 | ]) |
||
| 140 | ->add('timezone', TimezoneType::class, [ |
||
| 141 | 'required' => false, |
||
| 142 | 'attr' => ['class' => 'selectpicker', 'data-live-search' => true], |
||
| 143 | 'placeholder' => $this->trans->trans('user_settings.timezone.placeholder'), |
||
| 144 | 'label' => $this->trans->trans('user.timezone.label'), |
||
| 145 | 'preferred_choices' => ['Europe/Berlin'], |
||
| 146 | 'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
||
| 147 | ]) |
||
| 148 | ->add('theme', ChoiceType::class, [ |
||
| 149 | 'required' => false, |
||
| 150 | 'placeholder' => $this->trans->trans('user_settings.theme.placeholder'), |
||
| 151 | 'label' => $this->trans->trans('user.theme.label'), |
||
| 152 | 'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
||
| 153 | ]) |
||
| 154 | ->add('currency', CurrencyEntityType::class, [ |
||
| 155 | 'required' => false, |
||
| 156 | 'label' => $this->trans->trans('user.currency.label'), |
||
| 157 | 'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
||
| 158 | ]) |
||
| 159 | |||
| 160 | ->add('new_password', RepeatedType::class, [ |
||
| 161 | 'type' => PasswordType::class, |
||
| 162 | 'first_options' => ['label' => $this->trans->trans('user.settings.pw_new.label')], |
||
| 163 | 'second_options' => ['label' => $this->trans->trans('user.settings.pw_confirm.label')], |
||
| 164 | 'invalid_message' => 'password_must_match', |
||
| 165 | 'required' => false, |
||
| 166 | 'mapped' => false, |
||
| 167 | 'constraints' => [new Length([ |
||
| 168 | 'min' => 6, |
||
| 169 | 'max' => 128, |
||
| 170 | ])] |
||
| 171 | ]) |
||
| 172 | |||
| 173 | ->add('need_pw_change', CheckboxType::class, [ |
||
| 174 | 'required' => false, |
||
| 175 | 'label_attr' => ['class' => 'checkbox-custom'], |
||
| 176 | 'label' => $this->trans->trans('user.edit.needs_pw_change') |
||
| 177 | ]) |
||
| 178 | |||
| 179 | //Permission section |
||
| 180 | ->add('permissions', PermissionsType::class, [ |
||
| 181 | 'mapped' => false, |
||
| 182 | 'data' => $builder->getData(), |
||
| 183 | 'disabled' => !$this->security->isGranted('edit_permissions', $entity) |
||
| 184 | ]) |
||
| 185 | ; |
||
| 186 | /*->add('comment', CKEditorType::class, ['required' => false, |
||
| 187 | 'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint', |
||
| 188 | 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); */ |
||
| 189 | |||
| 190 | $this->additionalFormElements($builder, $options, $entity); |
||
| 191 | |||
| 192 | //Attachment section |
||
| 193 | $builder->add('attachments', CollectionType::class, [ |
||
| 194 | 'entry_type' => AttachmentFormType::class, |
||
| 195 | 'allow_add' => true, |
||
| 196 | 'allow_delete' => true, |
||
| 197 | 'label' => false, |
||
| 198 | 'entry_options' => [ |
||
| 199 | 'data_class' => $options['attachment_class'], |
||
| 200 | ], |
||
| 201 | 'by_reference' => false |
||
| 202 | ]); |
||
| 203 | |||
| 204 | //Buttons |
||
| 205 | $builder->add('save', SubmitType::class, [ |
||
| 206 | 'label' => $is_new ? $this->trans->trans('user.create') : $this->trans->trans('user.edit.save'), |
||
|
|
|||
| 207 | 'attr' => ['class' => $is_new ? 'btn-success' : ''] |
||
| 208 | ]) |
||
| 209 | ->add('reset', ResetType::class, [ |
||
| 210 | 'label' => $this->trans->trans('entity.edit.reset') |
||
| 211 | ]); |
||
| 218 | } |