Conditions | 55 |
Paths | > 20000 |
Total Lines | 259 |
Code Lines | 197 |
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 declare(strict_types=1); |
||
107 | public function getForm($action = false, $test = false) |
||
108 | { |
||
109 | $helper = \XoopsModules\Wgevents\Helper::getInstance(); |
||
110 | |||
111 | $eventHandler = $helper->getHandler('Event'); |
||
112 | $questionHandler = $helper->getHandler('Question'); |
||
113 | $answerHandler = $helper->getHandler('Answer'); |
||
114 | $permissionsHandler = $helper->getHandler('Permission'); |
||
115 | |||
116 | if (!$action) { |
||
117 | $action = $_SERVER['REQUEST_URI']; |
||
118 | } |
||
119 | $isAdmin = false; |
||
120 | if (\is_object($GLOBALS['xoopsUser']) && \is_object($GLOBALS['xoopsModule'])) { |
||
121 | $isAdmin = $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid()); |
||
122 | } |
||
123 | $answersExist = true; |
||
124 | // Title |
||
125 | if ($this->isNew()) { |
||
126 | $title = $test ? \_MA_WGEVENTS_QUESTIONS_PREVIEW : \_MA_WGEVENTS_REGISTRATION_ADD; |
||
127 | $answersExist = false; |
||
128 | } else { |
||
129 | $title =\_MA_WGEVENTS_REGISTRATION_EDIT; |
||
130 | } |
||
131 | |||
132 | $regEvid = $this->getVar('evid'); |
||
133 | $eventObj = $eventHandler->get($regEvid); |
||
134 | $permRegistrationsApprove = $permissionsHandler->getPermRegistrationsApprove($eventObj->getVar('submitter'), $eventObj->getVar('status')); |
||
135 | $eventFee = (float)$eventObj->getVar('fee'); |
||
136 | $eventRegisterMax = (int)$eventObj->getVar('register_max'); |
||
137 | $eventRegisterForceverif = (bool)$eventObj->getVar('register_forceverif'); |
||
138 | |||
139 | // Get Theme Form |
||
140 | \xoops_load('XoopsFormLoader'); |
||
141 | $form = new \XoopsThemeForm($title, 'formRegistration', $action, 'post', true); |
||
142 | $form->setExtra('enctype="multipart/form-data"'); |
||
143 | // Form Table events |
||
144 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_REGISTRATION_EVID, $eventObj->getVar('name'))); |
||
145 | $form->addElement(new \XoopsFormHidden('evid', $this->getVar('evid'))); |
||
146 | // Form select regSalutation |
||
147 | $regSalutationSelect = new \XoopsFormSelect(\_MA_WGEVENTS_REGISTRATION_SALUTATION, 'salutation', $this->getVar('salutation')); |
||
148 | $regSalutationSelect->addOption(Constants::SALUTATION_NONE, ' '); |
||
149 | $regSalutationSelect->addOption(Constants::SALUTATION_MEN, \_MA_WGEVENTS_REGISTRATION_SALUTATION_MEN); |
||
150 | $regSalutationSelect->addOption(Constants::SALUTATION_WOMEN, \_MA_WGEVENTS_REGISTRATION_SALUTATION_WOMEN); |
||
151 | $form->addElement($regSalutationSelect); |
||
152 | // Form select regFirstname |
||
153 | $regFirstname = new Forms\FormText(\_MA_WGEVENTS_REGISTRATION_FIRSTNAME, 'firstname', 50, 255, $this->getVar('firstname')); |
||
154 | $regFirstname->setPlaceholder(\_MA_WGEVENTS_REGISTRATION_FIRSTNAME_PLACEHOLDER); |
||
155 | $form->addElement($regFirstname); |
||
156 | // Form select regLastname |
||
157 | $regLastname = new Forms\FormText(\_MA_WGEVENTS_REGISTRATION_LASTNAME, 'lastname', 50, 255, $this->getVar('lastname')); |
||
158 | $regLastname->setPlaceholder(\_MA_WGEVENTS_REGISTRATION_LASTNAME_PLACEHOLDER); |
||
159 | $form->addElement($regLastname, true); |
||
160 | // Form select regEmail |
||
161 | $regEmailTray = new Forms\FormElementTray(\_MA_WGEVENTS_REGISTRATION_EMAIL, '<br>'); |
||
162 | $regEmail = new Forms\FormText('', 'email', 50, 255, $this->getVar('email')); |
||
163 | $regEmail->setPlaceholder(\_MA_WGEVENTS_REGISTRATION_EMAIL_PLACEHOLDER); |
||
164 | if ($eventRegisterForceverif) { |
||
165 | $regEmail->setDescription(_MA_WGEVENTS_EVENT_REGISTER_FORCEVERIF_INFO); |
||
166 | } |
||
167 | $regEmail->setExtra("onfocusout='emailValidation(\"email\", \"" . \sprintf(\_MA_WGEVENTS_INVALID_EMAIL, \_MA_WGEVENTS_REGISTRATION_EMAIL) . "\")'"); |
||
168 | $regEmailTray->addElement($regEmail, $eventRegisterForceverif); |
||
169 | // Form select regEmailSend |
||
170 | $regEmailSend = $this->isNew() ? 1 : $this->getVar('email_send'); |
||
171 | $regEmailRadio = new \XoopsFormRadioYN(\_MA_WGEVENTS_REGISTRATION_EMAIL_CONFIRM, 'email_send', $regEmailSend); |
||
172 | $regEmailTray->addElement($regEmailRadio); |
||
173 | $form->addElement($regEmailTray); |
||
174 | // get all questions |
||
175 | $crQuestion = new \CriteriaCompo(); |
||
176 | $crQuestion->add(new \Criteria('evid', $regEvid)); |
||
177 | $crQuestion->setSort('weight ASC, id'); |
||
178 | $crQuestion->setOrder('DESC'); |
||
179 | $questionsCount = $questionHandler->getCount($crQuestion); |
||
180 | if ($questionsCount > 0) { |
||
181 | $questionsAll = $questionHandler->getAll($crQuestion); |
||
182 | foreach (\array_keys($questionsAll) as $queId) { |
||
183 | $formelementsHandler = new FormelementsHandler(); |
||
184 | $formelementsHandler->name = 'ans_id_' . $queId; |
||
185 | $queType = (int)$questionsAll[$queId]->getVar('type'); |
||
186 | $addValue = (string)$questionsAll[$queId]->getVar('values'); |
||
187 | $formelementsHandler->type = $queType; |
||
188 | $formelementsHandler->caption = $questionsAll[$queId]->getVar('caption'); |
||
189 | if ($answersExist) { |
||
190 | $value = ''; |
||
191 | // get answers for this questions |
||
192 | $crAnswer = new \CriteriaCompo(); |
||
193 | $crAnswer->add(new \Criteria('regid', $this->getVar('id'))); |
||
194 | $crAnswer->add(new \Criteria('queid', $queId)); |
||
195 | $answersCount = $answerHandler->getCount($crAnswer); |
||
196 | if ($answersCount > 0) { |
||
197 | $answersAll = $answerHandler->getAll($crAnswer); |
||
198 | foreach (\array_keys($answersAll) as $ansId) { |
||
199 | switch ($queType) { |
||
200 | case Constants::FIELD_DATE: |
||
201 | $answerDateObj = \DateTime::createFromFormat(\_SHORTDATESTRING, $answersAll[$ansId]->getVar('text')); |
||
202 | $value = $answerDateObj->getTimestamp(); |
||
203 | break; |
||
204 | case Constants::FIELD_COMBOBOX: |
||
205 | case Constants::FIELD_CHECKBOX: |
||
206 | $ansText = $answersAll[$ansId]->getVar('text', 'n'); |
||
207 | $value = \unserialize($ansText, ['allowed_classes' => false]); |
||
208 | break; |
||
209 | case Constants::FIELD_SELECTBOX: |
||
210 | $ansText = $answersAll[$ansId]->getVar('text', 'n'); |
||
211 | $value = (string)\unserialize($ansText, ['allowed_classes' => false]); |
||
212 | break; |
||
213 | case 0: |
||
214 | default: |
||
215 | $value = $answersAll[$ansId]->getVar('text'); |
||
216 | break; |
||
217 | } |
||
218 | } |
||
219 | } |
||
220 | $formelementsHandler->value = $value; |
||
221 | //} else { |
||
222 | //TODO |
||
223 | } |
||
224 | if (Constants::FIELD_RADIO == $queType || |
||
225 | //Constants::FIELD_SELECTBOX == $queType || |
||
226 | Constants::FIELD_CHECKBOX == $queType || |
||
227 | Constants::FIELD_COMBOBOX == $queType) { |
||
228 | $formelementsHandler->optionsArr = \unserialize($addValue, ['allowed_classes' => false]); |
||
229 | } |
||
230 | /**/ |
||
231 | $required = (bool)$questionsAll[$queId]->getVar('required'); |
||
232 | if ($isAdmin) { |
||
233 | $required = false; |
||
234 | } |
||
235 | if (Constants::FIELD_SELECTBOX == $queType) { |
||
236 | //required selectboxes get a blank link in order to force user to input |
||
237 | $optionsSB = []; |
||
238 | if ($required) { |
||
239 | $optionsSB[''] = ' '; |
||
240 | } |
||
241 | foreach (\unserialize($addValue, ['allowed_classes' => false]) as $optSB) { |
||
242 | $optionsSB[] = $optSB; |
||
243 | } |
||
244 | $formelementsHandler->optionsArr = $optionsSB; |
||
245 | } |
||
246 | |||
247 | if (Constants::FIELD_LABEL == $queType) { |
||
248 | $desc = \preg_replace('/\r\n|\r|\n/', '<br>', $questionsAll[$queId]->getVar('desc', 'e')); |
||
249 | $formelementsHandler->value = $desc; |
||
250 | } |
||
251 | $formelementsHandler->placeholder = $questionsAll[$queId]->getVar('placeholder'); |
||
252 | $formelementsHandler->desc = $questionsAll[$queId]->getVar('desc'); |
||
253 | $form->addElement($formelementsHandler->render(), $required); |
||
254 | $form->addElement(new \XoopsFormHidden('type[' . $questionsAll[$queId]->getVar('id') . ']', $questionsAll[$queId]->getVar('type'))); |
||
255 | $form->addElement(new \XoopsFormHidden('ans_id[' . $questionsAll[$queId]->getVar('id') . ']', $questionsAll[$queId]->getVar('id'))); |
||
256 | } |
||
257 | unset($questions); |
||
258 | } |
||
259 | // Form checkbox regGdpr |
||
260 | $valueGdpr = $permRegistrationsApprove ? 1 : ''; |
||
261 | $regGdpr = new \XoopsFormCheckBox(\_MA_WGEVENTS_REGISTRATION_GDPR, 'gdpr', $valueGdpr); |
||
262 | $regGdpr->addOption(1, \_MA_WGEVENTS_REGISTRATION_GDPR_VALUE); |
||
263 | $form->addElement($regGdpr, true); |
||
264 | // Form Text Date Select regFinancial |
||
265 | // Form Text Date Select regPaidamount |
||
266 | $regFinancial = $this->isNew() ? Constants::FINANCIAL_UNPAID : $this->getVar('financial'); |
||
267 | $default0 = '0' . $helper->getConfig('sep_comma') . '00'; |
||
268 | $regPaidamount = $this->isNew() ? $default0 : Utility::FloatToString($this->getVar('paidamount')); |
||
269 | if ($eventFee > 0 && $permRegistrationsApprove && !$test) { |
||
270 | $regFinancialRadio = new \XoopsFormRadio(\_MA_WGEVENTS_REGISTRATION_FINANCIAL, 'financial', $regFinancial); |
||
271 | $regFinancialRadio->addOption(Constants::FINANCIAL_UNPAID, \_MA_WGEVENTS_REGISTRATION_FINANCIAL_UNPAID); |
||
272 | $regFinancialRadio->addOption(Constants::FINANCIAL_PAID, \_MA_WGEVENTS_REGISTRATION_FINANCIAL_PAID); |
||
273 | $form->addElement($regFinancialRadio, true); |
||
274 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_REGISTRATION_PAIDAMOUNT, 'paidamount', 20, 150, $regPaidamount)); |
||
275 | } else { |
||
276 | if (!$this->isNew() && $eventFee > 0 && $test) { |
||
277 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_REGISTRATION_FINANCIAL, Utility::getFinancialText($regFinancial))); |
||
278 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_REGISTRATION_PAIDAMOUNT, $regPaidamount)); |
||
279 | } |
||
280 | $form->addElement(new \XoopsFormHidden('financial', $regFinancial)); |
||
281 | $form->addElement(new \XoopsFormHidden('paidamount', $regPaidamount)); |
||
282 | } |
||
283 | // Form Radio Yes/No regListwait |
||
284 | $regListwait = $this->isNew() ? 0 : (int)$this->getVar('listwait'); |
||
285 | if ($eventRegisterMax > 0 && $permRegistrationsApprove && !$test) { |
||
286 | $form->addElement(new \XoopsFormRadioYN(\_MA_WGEVENTS_REGISTRATION_LISTWAIT, 'listwait', $regListwait)); |
||
287 | } else { |
||
288 | if ($eventRegisterMax > 0 && $regListwait > 0 && $test) { |
||
289 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_REGISTRATION_LISTWAIT, \_YES)); |
||
290 | } |
||
291 | $form->addElement(new \XoopsFormHidden('listwait', $regListwait)); |
||
292 | } |
||
293 | // Form Text IP resIp |
||
294 | $regIp = $_SERVER['REMOTE_ADDR']; |
||
295 | // Form Text Select resStatus |
||
296 | if ($this->isNew()) { |
||
297 | $regStatus = Constants::STATUS_SUBMITTED; |
||
298 | if ($permissionsHandler->getPermRegistrationsVerif()) { |
||
299 | $regStatus = Constants::STATUS_VERIFIED; |
||
300 | } |
||
301 | if ($permRegistrationsApprove) { |
||
302 | $regStatus = Constants::STATUS_APPROVED; |
||
303 | } |
||
304 | } else { |
||
305 | $regStatus = $this->getVar('status'); |
||
306 | } |
||
307 | // Form Text resVerifcode |
||
308 | $resVerifkey = $this->getVar('verifkey'); |
||
309 | // Form Text Date Select regDatecreated |
||
310 | $regDatecreated = $this->isNew() ? \time() : $this->getVar('datecreated'); |
||
311 | // Form Select User resSubmitter |
||
312 | $regSubmitter = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0; |
||
313 | if ($permRegistrationsApprove && !$test) { |
||
314 | $regStatusSelect = new \XoopsFormSelect(\_MA_WGEVENTS_STATUS, 'status', $regStatus); |
||
315 | $regStatusSelect->addOption(Constants::STATUS_NONE, \_MA_WGEVENTS_STATUS_NONE); |
||
316 | $regStatusSelect->addOption(Constants::STATUS_OFFLINE, \_MA_WGEVENTS_STATUS_OFFLINE); |
||
317 | $regStatusSelect->addOption(Constants::STATUS_SUBMITTED, \_MA_WGEVENTS_STATUS_SUBMITTED); |
||
318 | $regStatusSelect->addOption(Constants::STATUS_VERIFIED, \_MA_WGEVENTS_STATUS_VERIFIED); |
||
319 | $regStatusSelect->addOption(Constants::STATUS_APPROVED, \_MA_WGEVENTS_STATUS_APPROVED); |
||
320 | $form->addElement($regStatusSelect, true); |
||
321 | } else { |
||
322 | if (!$this->isNew() && !$test) { |
||
323 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_STATUS, Utility::getStatusText($regStatus))); |
||
324 | } |
||
325 | $form->addElement(new \XoopsFormHidden('status', $regStatus)); |
||
326 | } |
||
327 | if ($isAdmin) { |
||
328 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_REGISTRATION_IP, 'ip', 20, 150, $this->getVar('ip'))); |
||
329 | $form->addElement(new \XoopsFormText(\_MA_WGEVENTS_REGISTRATION_VERIFKEY, 'verifkey', 20, 150, $resVerifkey)); |
||
330 | // Form Text Date Select queDatecreated |
||
331 | $form->addElement(new \XoopsFormTextDateSelect(\_MA_WGEVENTS_DATECREATED, 'datecreated', '', $regDatecreated)); |
||
332 | $form->addElement(new \XoopsFormSelectUser(\_MA_WGEVENTS_SUBMITTER, 'submitter', false, $regSubmitter)); |
||
333 | } else { |
||
334 | $form->addElement(new \XoopsFormHidden('ip', $regIp)); |
||
335 | $form->addElement(new \XoopsFormHidden('verifkey', $resVerifkey)); |
||
336 | $form->addElement(new \XoopsFormHidden('datecreated_int', \time())); |
||
337 | $form->addElement(new \XoopsFormHidden('submitter', $regSubmitter)); |
||
338 | if (!$this->isNew() && !$test) { |
||
339 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_DATECREATED, \formatTimestamp($regDatecreated, 's'))); |
||
340 | $form->addElement(new \XoopsFormLabel(\_MA_WGEVENTS_SUBMITTER, \XoopsUser::getUnameFromId($regSubmitter))); |
||
341 | } |
||
342 | } |
||
343 | // To Save |
||
344 | $form->addElement(new \XoopsFormHidden('id', $this->getVar('id'))); |
||
345 | $form->addElement(new \XoopsFormHidden('op', 'save')); |
||
346 | $form->addElement(new \XoopsFormHidden('start', $this->start)); |
||
347 | $form->addElement(new \XoopsFormHidden('limit', $this->limit)); |
||
348 | $form->addElement(new \XoopsFormHidden('redir', $this->redir)); |
||
349 | $form->addElement(new \XoopsFormHidden('verifkeyEdit', $this->verifkeyEdit)); |
||
350 | // button tray |
||
351 | $buttonTray = new \XoopsFormElementTray(''); |
||
352 | $buttonBack = new Forms\FormButton('', 'cancel', \_CANCEL, 'button'); |
||
353 | $buttonBack->setExtra('onclick="history.go(-1);return true;"'); |
||
354 | $buttonBack->setClass('btn-danger'); |
||
355 | $buttonTray->addElement($buttonBack); |
||
356 | if (!$test) { |
||
357 | $buttonReset = new Forms\FormButton('', 'reset', \_RESET, 'reset'); |
||
358 | $buttonReset->setClass('btn-warning'); |
||
359 | $buttonTray->addElement($buttonReset); |
||
360 | $buttonSubmit = new Forms\FormButton('', '_submit', \_MA_WGEVENTS_SAVE, 'submit'); |
||
361 | $buttonSubmit->setClass('btn-primary'); |
||
362 | $buttonTray->addElement($buttonSubmit); |
||
363 | } |
||
364 | $form->addElement($buttonTray); |
||
365 | return $form; |
||
366 | } |
||
449 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths