Conditions | 5 |
Paths | 1 |
Total Lines | 116 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
77 | protected function lazy_get_children() |
||
78 | { |
||
79 | $values = $this->values; |
||
80 | $user = $this->user; |
||
81 | $uid = $values[User::UID]; |
||
82 | $languages = $this->app->locale['languages']; |
||
83 | |||
84 | uasort($languages, 'ICanBoogie\unaccent_compare_ci'); |
||
85 | |||
86 | $administer = $user->has_permission(Module::PERMISSION_MANAGE, $this->module); |
||
87 | |||
88 | return array_merge(parent::lazy_get_children(), [ |
||
89 | |||
90 | # |
||
91 | # name group |
||
92 | # |
||
93 | |||
94 | User::FIRSTNAME => new Text([ |
||
95 | |||
96 | Group::LABEL => 'firstname' |
||
97 | |||
98 | ]), |
||
99 | |||
100 | User::LASTNAME => new Text([ |
||
101 | |||
102 | Group::LABEL => 'lastname' |
||
103 | |||
104 | ]), |
||
105 | |||
106 | User::NICKNAME => new Text([ |
||
107 | |||
108 | Group::LABEL => 'Nickname' |
||
109 | |||
110 | ]), |
||
111 | |||
112 | User::USERNAME => $administer ? new Text([ |
||
113 | |||
114 | Group::LABEL => 'username', |
||
115 | Element::REQUIRED => true |
||
116 | |||
117 | ]) : null, |
||
118 | |||
119 | User::NAME_AS => $this->create_control_for_name_as(), |
||
120 | |||
121 | # |
||
122 | # connection group |
||
123 | # |
||
124 | |||
125 | User::EMAIL => new Text([ |
||
126 | |||
127 | Group::LABEL => 'email', |
||
128 | Element::GROUP => 'connection', |
||
129 | Element::REQUIRED => true, |
||
130 | Element::VALIDATION => 'email', |
||
131 | |||
132 | 'autocomplete' => 'off' |
||
133 | |||
134 | ]), |
||
135 | |||
136 | User::PASSWORD => new Text([ |
||
137 | |||
138 | Element::LABEL => 'password', |
||
139 | Element::LABEL_POSITION => 'above', |
||
140 | Element::DESCRIPTION => 'password_' . ($uid ? 'update' : 'new'), |
||
141 | Element::GROUP => 'connection', |
||
142 | |||
143 | 'autocomplete' => 'off', |
||
144 | 'type' => 'password', |
||
145 | 'value' => '' |
||
146 | |||
147 | ]), |
||
148 | |||
149 | User::PASSWORD . '-verify' => new Text([ |
||
150 | |||
151 | Element::LABEL => 'password_confirm', |
||
152 | Element::LABEL_POSITION => 'above', |
||
153 | Element::DESCRIPTION => 'password_confirm', |
||
154 | Element::GROUP => 'connection', |
||
155 | |||
156 | 'autocomplete' => 'off', |
||
157 | 'type' => 'password', |
||
158 | 'value' => '' |
||
159 | |||
160 | ]), |
||
161 | |||
162 | User::IS_ACTIVATED => ($uid == 1 || !$administer) ? null : new Element(Element::TYPE_CHECKBOX, [ |
||
163 | |||
164 | Element::LABEL => 'is_activated', |
||
165 | Element::GROUP => 'connection', |
||
166 | Element::DESCRIPTION => 'is_activated' |
||
167 | |||
168 | ]), |
||
169 | |||
170 | User::ROLES => $this->create_control_for_role(), |
||
171 | |||
172 | User::LANGUAGE => new Element('select', [ |
||
173 | |||
174 | Group::LABEL => 'language', |
||
175 | Element::GROUP => 'advanced', |
||
176 | Element::DESCRIPTION => 'language', |
||
177 | Element::OPTIONS => [ null => '' ] + $languages |
||
178 | |||
179 | ]), |
||
180 | |||
181 | 'timezone' => new Widget\TimeZone([ |
||
182 | |||
183 | Group::LABEL => 'timezone', |
||
184 | Element::GROUP => 'advanced', |
||
185 | Element::DESCRIPTION =>'timezone' |
||
186 | |||
187 | ]), |
||
188 | |||
189 | User::RESTRICTED_SITES => $this->create_control_for_restricted_sites_ids() |
||
190 | |||
191 | ]); |
||
192 | } |
||
193 | |||
347 |
This class constant has been deprecated.