Conditions | 3 |
Paths | 1 |
Total Lines | 101 |
Code Lines | 70 |
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 |
||
68 | public function buildForm(FormBuilderInterface $builder, array $options) |
||
69 | { |
||
70 | /** @var StructuralDBElement $entity */ |
||
71 | $entity = $options['data']; |
||
72 | $is_new = $entity->getID() === null; |
||
73 | |||
74 | $builder |
||
75 | ->add('name', TextType::class, [ |
||
76 | 'empty_data' => '', |
||
77 | 'label' => $this->trans->trans('user.username.label'), |
||
78 | 'attr' => ['placeholder' => $this->trans->trans('user.username.placeholder')], |
||
79 | 'disabled' => !$this->security->isGranted('edit_username', $entity), |
||
80 | ]) |
||
81 | |||
82 | ->add('group', StructuralEntityType::class, [ |
||
83 | 'class' => Group::class, |
||
84 | 'required' => false, |
||
85 | 'label' => $this->trans->trans('group.label'), |
||
86 | 'disable_not_selectable' => true, |
||
87 | 'disabled' => !$this->security->isGranted('change_group', $entity), ]) |
||
88 | |||
89 | ->add('first_name', TextType::class, [ |
||
90 | 'empty_data' => '', |
||
91 | 'label' => $this->trans->trans('user.firstName.label'), |
||
92 | 'attr' => ['placeholder' => $this->trans->trans('user.firstName.placeholder')], 'required' => false, |
||
93 | 'disabled' => !$this->security->isGranted('edit_infos', $entity), |
||
94 | ]) |
||
95 | |||
96 | ->add('last_name', TextType::class, [ |
||
97 | 'empty_data' => '', |
||
98 | 'label' => $this->trans->trans('user.lastName.label'), |
||
99 | 'attr' => ['placeholder' => $this->trans->trans('user.lastName.placeholder')], |
||
100 | 'required' => false, |
||
101 | 'disabled' => !$this->security->isGranted('edit_infos', $entity), |
||
102 | ]) |
||
103 | |||
104 | ->add('email', TextType::class, [ |
||
105 | 'empty_data' => '', |
||
106 | 'label' => $this->trans->trans('user.email.label'), |
||
107 | 'attr' => ['placeholder' => $this->trans->trans('user.email.placeholder')], |
||
108 | 'required' => false, |
||
109 | 'disabled' => !$this->security->isGranted('edit_infos', $entity), ]) |
||
110 | |||
111 | |||
112 | ->add('department', TextType::class, [ |
||
113 | 'empty_data' => '', |
||
114 | 'label' => $this->trans->trans('user.department.label'), |
||
115 | 'attr' => ['placeholder' => $this->trans->trans('user.department.placeholder')], |
||
116 | 'required' => false, |
||
117 | 'disabled' => !$this->security->isGranted('edit_infos', $entity), |
||
118 | ]) |
||
119 | |||
120 | //Config section |
||
121 | ->add('language', LanguageType::class, [ |
||
122 | 'required' => false, |
||
123 | 'attr' => ['class' => 'selectpicker', 'data-live-search' => true], |
||
124 | 'placeholder' => $this->trans->trans('user_settings.language.placeholder'), |
||
125 | 'label' => $this->trans->trans('user.language_select'), |
||
126 | 'preferred_choices' => ['en', 'de'], |
||
127 | 'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
||
128 | ]) |
||
129 | ->add('timezone', TimezoneType::class, [ |
||
130 | 'required' => false, |
||
131 | 'attr' => ['class' => 'selectpicker', 'data-live-search' => true], |
||
132 | 'placeholder' => $this->trans->trans('user_settings.timezone.placeholder'), |
||
133 | 'label' => $this->trans->trans('user.timezone.label'), |
||
134 | 'preferred_choices' => ['Europe/Berlin'], |
||
135 | 'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
||
136 | ]) |
||
137 | ->add('theme', ChoiceType::class, [ |
||
138 | 'required' => false, |
||
139 | 'placeholder' => $this->trans->trans('user_settings.theme.placeholder'), |
||
140 | 'label' => $this->trans->trans('user.theme.label'), |
||
141 | 'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
||
142 | ]) |
||
143 | ->add('currency', CurrencyEntityType::class, [ |
||
144 | 'required' => false, |
||
145 | 'label' => $this->trans->trans('user.currency.label'), |
||
146 | 'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
||
147 | ]) |
||
148 | |||
149 | //Permission section |
||
150 | ->add('permissions', PermissionsType::class, [ |
||
151 | 'mapped' => false, |
||
152 | 'data' => $builder->getData(), |
||
153 | 'disabled' => !$this->security->isGranted('edit_permissions', $entity) |
||
154 | ]) |
||
155 | ; |
||
156 | /*->add('comment', CKEditorType::class, ['required' => false, |
||
157 | 'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint', |
||
158 | 'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); */ |
||
159 | |||
160 | $this->additionalFormElements($builder, $options, $entity); |
||
161 | |||
162 | //Buttons |
||
163 | $builder->add('save', SubmitType::class, [ |
||
164 | 'label' => $is_new ? $this->trans->trans('user.create') : $this->trans->trans('user.edit.save'), |
||
|
|||
165 | 'attr' => ['class' => $is_new ? 'btn-success' : ''] |
||
166 | ]) |
||
167 | ->add('reset', ResetType::class, [ |
||
168 | 'label' => $this->trans->trans('entity.edit.reset') |
||
169 | ]); |
||
176 | } |