Conditions | 10 |
Paths | 33 |
Total Lines | 102 |
Code Lines | 64 |
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 |
||
30 | protected function configureFormFields(FormMapper $formMapper): void |
||
31 | { |
||
32 | // Forbid edition of other admin account except for super admin |
||
33 | if (($this->getSubject()->hasRole('ROLE_SUPER_ADMIN') |
||
34 | && $this->getUser()->getId() !== $this->getSubject()->getId())) { |
||
35 | throw new AccessDeniedException('u can\'t edit this user'); // TODO : do better |
||
36 | } |
||
37 | |||
38 | $now = new \DateTime(); |
||
39 | |||
40 | $formMapper |
||
41 | ->with('admin.user.label.id', ['class' => 'col-md-4']) |
||
42 | //->add('username') |
||
43 | ->add('email', null, [ |
||
44 | 'label' => 'admin.user.email.label', |
||
45 | ]) |
||
46 | ->add('plainPassword', TextType::class, [ |
||
47 | 'required' => (! $this->getSubject() || null === $this->getSubject()->getId()), |
||
48 | 'label' => 'admin.user.password.label', |
||
49 | ]) |
||
50 | ->end(); |
||
51 | |||
52 | $formMapper |
||
53 | ->with('admin.user.label.profile', ['class' => 'col-md-4']); |
||
54 | |||
55 | if ($this->exists('DateOfBirth')) { |
||
56 | $formMapper->add( |
||
57 | 'dateOfBirth', |
||
58 | DatePickerType::class, |
||
59 | [ |
||
60 | 'years' => range(1900, $now->format('Y')), |
||
61 | 'dp_min_date' => '1-1-1900', |
||
62 | 'dp_max_date' => $now->format('c'), |
||
63 | 'required' => false, |
||
64 | 'label' => 'admin.user.dateOfBirth.label', |
||
65 | ] |
||
66 | ); |
||
67 | } |
||
68 | if ($this->exists('firstname')) { |
||
69 | $formMapper->add( |
||
70 | 'firstname', |
||
71 | TextType::class, |
||
72 | [ |
||
73 | 'required' => false, |
||
74 | 'label' => 'admin.user.firstname.label', |
||
75 | ] |
||
76 | ); |
||
77 | } |
||
78 | if ($this->exists('lastname')) { |
||
79 | $formMapper->add( |
||
80 | 'lastname', |
||
81 | TextType::class, |
||
82 | [ |
||
83 | 'required' => false, |
||
84 | 'label' => 'admin.user.lastname.label', |
||
85 | ] |
||
86 | ); |
||
87 | } |
||
88 | if ($this->exists('city')) { |
||
89 | $formMapper->add( |
||
90 | 'city', |
||
91 | TextType::class, |
||
92 | [ |
||
93 | 'required' => false, |
||
94 | 'label' => 'admin.user.city.label', |
||
95 | ] |
||
96 | ); |
||
97 | } |
||
98 | if ($this->exists('phone')) { |
||
99 | $formMapper->add( |
||
100 | 'phone', |
||
101 | TextType::class, |
||
102 | [ |
||
103 | 'required' => false, |
||
104 | 'label' => 'admin.user.phone.label', |
||
105 | ] |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | $formMapper->end() |
||
110 | |||
111 | ->with('admin.user.label.security', ['class' => 'col-md-4']) |
||
112 | ->add('roles', ImmutableArrayType::class, [ |
||
113 | 'label' => false, |
||
114 | 'keys' => [ |
||
115 | ['0', ChoiceType::class, [ |
||
116 | 'required' => false, |
||
117 | 'label' => 'admin.user.role.label', |
||
118 | 'choices' => $this->getUser()->hasRole('ROLE_SUPER_ADMIN') ? [ |
||
119 | 'admin.user.role.super_admin' => 'ROLE_SUPER_ADMIN', |
||
120 | 'admin.user.role.admin' => 'ROLE_ADMIN', |
||
121 | 'admin.user.role.editor' => 'ROLE_EDITOR', |
||
122 | 'admin.user.role.user' => 'ROLE_USER', |
||
123 | ] : [ |
||
124 | 'admin.user.role.admin' => 'ROLE_ADMIN', |
||
125 | 'admin.user.role.editor' => 'ROLE_EDITOR', |
||
126 | 'admin.user.role.user' => 'ROLE_USER', |
||
127 | ], |
||
128 | ]], |
||
129 | ], |
||
130 | ]) |
||
131 | ->end(); |
||
132 | } |
||
191 |