Conditions | 36 |
Paths | 18027 |
Total Lines | 188 |
Code Lines | 127 |
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 |
||
54 | public $toselect; |
||
55 | public $contextpage; |
||
56 | public $backtopage; |
||
57 | public $mode; |
||
58 | public $sall; |
||
59 | public $filter; |
||
60 | public $search_ref; |
||
61 | public $search_lastname; |
||
62 | public $search_login; |
||
63 | public $search_email; |
||
64 | public $type; |
||
65 | public $status; |
||
66 | public $optioncss; |
||
67 | public $limit; |
||
68 | public $sortfield; |
||
69 | public $sortorder; |
||
70 | public $page; |
||
71 | public $pagenext; |
||
72 | public $label; |
||
73 | public $morphy; |
||
74 | public $offset; |
||
75 | public $pageprev; |
||
76 | public $subscription; |
||
77 | public $amount; |
||
78 | public $duration_value; |
||
79 | public $duration_unit; |
||
80 | public $vote; |
||
81 | public $comment; |
||
82 | public $mail_valid; |
||
83 | public $caneditamount; |
||
84 | |||
85 | /** |
||
86 | * \file htdocs/adherents/type.php |
||
87 | * \ingroup member |
||
88 | * \brief Member's type setup |
||
89 | */ |
||
90 | public function doIndex(): bool |
||
91 | { |
||
92 | global $conf; |
||
93 | global $db; |
||
94 | global $user; |
||
95 | global $hookmanager; |
||
96 | global $user; |
||
97 | global $menumanager; |
||
98 | global $langs; |
||
99 | |||
100 | // Load translation files required by the page |
||
101 | $this->langs->load("members"); |
||
102 | |||
103 | $action = $this->filterPost('action', 'aZ09'); |
||
104 | if ($action === 'create') { |
||
105 | $this->template = '/page/adherent/type_edit'; |
||
106 | return true; |
||
107 | } |
||
108 | |||
109 | if ($action === 'cancel') { |
||
110 | $this->template = '/page/adherent/type_list'; |
||
111 | return true; |
||
112 | } |
||
113 | |||
114 | /* |
||
115 | * Actions |
||
116 | */ |
||
117 | |||
118 | if ($this->filterPost('button_removefilter_x', 'alpha') || $this->filterPost('button_removefilter_x', 'alpha') || $this->filterPost('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers |
||
119 | $search_ref = ""; |
||
120 | $search_lastname = ""; |
||
121 | $search_login = ""; |
||
122 | $search_email = ""; |
||
123 | $type = ""; |
||
124 | $sall = ""; |
||
125 | } |
||
126 | |||
127 | if ($this->filterPost('cancel', 'alpha')) { |
||
128 | $action = 'list'; |
||
129 | $massaction = ''; |
||
130 | } |
||
131 | |||
132 | if (!$this->filterPost('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { |
||
133 | $massaction = ''; |
||
134 | } |
||
135 | |||
136 | if ($cancel) { |
||
|
|||
137 | $action = ''; |
||
138 | |||
139 | if (!empty($backtopage)) { |
||
140 | header("Location: " . $backtopage); |
||
141 | exit; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | if ($action == 'add' && $user->hasRight('adherent', 'configurer')) { |
||
146 | $this->object->label = trim($label); |
||
147 | $this->object->morphy = trim($morphy); |
||
148 | $this->object->status = (int)$status; |
||
149 | $this->object->subscription = (int)$subscription; |
||
150 | $this->object->amount = ($amount == '' ? '' : price2num($amount, 'MT')); |
||
151 | $this->object->caneditamount = $caneditamount; |
||
152 | $this->object->duration_value = $duration_value; |
||
153 | $this->object->duration_unit = $duration_unit; |
||
154 | $this->object->note_public = trim($comment); |
||
155 | $this->object->note_private = ''; |
||
156 | $this->object->mail_valid = trim($mail_valid); |
||
157 | $this->object->vote = (int)$vote; |
||
158 | |||
159 | // Fill array 'array_options' with data from add form |
||
160 | $ret = $extrafields->setOptionalsFromPost(null, $this->object); |
||
161 | if ($ret < 0) { |
||
162 | $error++; |
||
163 | } |
||
164 | |||
165 | if (empty($this->object->label)) { |
||
166 | $error++; |
||
167 | setEventMessages($this->langs->trans("ErrorFieldRequired", $this->langs->transnoentities("Label")), null, 'errors'); |
||
168 | } else { |
||
169 | $sql = "SELECT libelle FROM " . MAIN_DB_PREFIX . "adherent_type WHERE libelle = '" . $this->db->escape($this->object->label) . "'"; |
||
170 | $sql .= " WHERE entity IN (" . getEntity('member_type') . ")"; |
||
171 | $result = $this->db->query($sql); |
||
172 | $num = null; |
||
173 | if ($result) { |
||
174 | $num = $this->db->num_rows($result); |
||
175 | } |
||
176 | if ($num) { |
||
177 | $error++; |
||
178 | $this->langs->load("errors"); |
||
179 | setEventMessages($this->langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors'); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | if (!$error) { |
||
184 | $id = $this->object->create($user); |
||
185 | if ($id > 0) { |
||
186 | header("Location: " . $_SERVER['PHP_SELF']); |
||
187 | exit; |
||
188 | } else { |
||
189 | setEventMessages($this->object->error, $this->object->errors, 'errors'); |
||
190 | $action = 'create'; |
||
191 | } |
||
192 | } else { |
||
193 | $action = 'create'; |
||
194 | } |
||
195 | } |
||
196 | |||
197 | if ($action == 'update' && $user->hasRight('adherent', 'configurer')) { |
||
198 | $this->object->fetch($this->rowid); |
||
199 | |||
200 | $this->object->oldcopy = dol_clone($this->object, 2); |
||
201 | |||
202 | $this->object->label = trim($label); |
||
203 | $this->object->morphy = trim($morphy); |
||
204 | $this->object->status = (int)$status; |
||
205 | $this->object->subscription = (int)$subscription; |
||
206 | $this->object->amount = ($amount == '' ? '' : price2num($amount, 'MT')); |
||
207 | $this->object->caneditamount = $caneditamount; |
||
208 | $this->object->duration_value = $duration_value; |
||
209 | $this->object->duration_unit = $duration_unit; |
||
210 | $this->object->note_public = trim($comment); |
||
211 | $this->object->note_private = ''; |
||
212 | $this->object->mail_valid = trim($mail_valid); |
||
213 | $this->object->vote = (bool)trim($vote); |
||
214 | |||
215 | // Fill array 'array_options' with data from add form |
||
216 | $ret = $extrafields->setOptionalsFromPost(null, $this->object, '@GETPOSTISSET'); |
||
217 | if ($ret < 0) { |
||
218 | $error++; |
||
219 | } |
||
220 | |||
221 | $ret = $this->object->update($user); |
||
222 | |||
223 | if ($ret >= 0 && !count($this->object->errors)) { |
||
224 | setEventMessages($this->langs->trans("MemberTypeModified"), null, 'mesgs'); |
||
225 | } else { |
||
226 | setEventMessages($this->object->error, $this->object->errors, 'errors'); |
||
227 | } |
||
228 | |||
229 | header("Location: " . $_SERVER['PHP_SELF'] . "?rowid=" . $this->object->id); |
||
230 | exit; |
||
231 | } |
||
232 | |||
233 | if ($action == 'confirm_delete' && $user->hasRight('adherent', 'configurer')) { |
||
234 | $this->object->fetch($this->rowid); |
||
235 | $res = $this->object->delete($user); |
||
236 | |||
237 | if ($res > 0) { |
||
238 | setEventMessages($this->langs->trans("MemberTypeDeleted"), null, 'mesgs'); |
||
239 | header("Location: " . $_SERVER['PHP_SELF']); |
||
240 | exit; |
||
241 | } else { |
||
242 | setEventMessages($this->langs->trans("MemberTypeCanNotBeDeleted"), null, 'errors'); |
||
347 |