| Conditions | 14 |
| Paths | 768 |
| Total Lines | 84 |
| Code Lines | 60 |
| 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); |
||
| 35 | public function __construct(\XoopsUser $user, $profile, $step = null) |
||
| 36 | { |
||
| 37 | global $opkey; // should be set in register.php |
||
| 38 | if (empty($opkey)) { |
||
| 39 | $opkey = 'profile_opname'; |
||
| 40 | } |
||
| 41 | $next_opname = 'op' . \random_int(10000, 99999); |
||
| 42 | $_SESSION[$opkey] = $next_opname; |
||
| 43 | require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
||
| 44 | if (empty($GLOBALS['xoopsConfigUser'])) { |
||
| 45 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 46 | $configHandler = \xoops_getHandler('config'); |
||
| 47 | $GLOBALS['xoopsConfigUser'] = $configHandler->getConfigsByCat(\XOOPS_CONF_USER); |
||
| 48 | } |
||
| 49 | $action = $_SERVER['REQUEST_URI']; |
||
| 50 | $step_no = $step['step_no']; |
||
| 51 | $use_token = $step['step_no'] > 0; // ? true : false; |
||
| 52 | parent::__construct($step['step_name'], 'regform', $action, 'post', $use_token); |
||
| 53 | if ($step['step_desc']) { |
||
| 54 | $this->addElement(new XoopsFormLabel('', $step['step_desc'])); |
||
| 55 | } |
||
| 56 | if (1 == $step_no) { |
||
| 57 | //$uname_size = $GLOBALS['xoopsConfigUser']['maxuname'] < 35 ? $GLOBALS['xoopsConfigUser']['maxuname'] : 35; |
||
| 58 | $elements[0][] = [ |
||
|
|
|||
| 59 | 'element' => new \XoopsFormText(\_MD_SUICO_NICKNAME, 'uname', 35, $GLOBALS['xoopsConfigUser']['maxuname'], $user->getVar('uname', 'e')), |
||
| 60 | 'required' => true, |
||
| 61 | ]; |
||
| 62 | $weights[0][] = 0; |
||
| 63 | $elements[0][] = ['element' => new \XoopsFormText(\_MD_SUICO_EMAILADDRESS, 'email', 35, 255, $user->getVar('email', 'e')), 'required' => true]; |
||
| 64 | $weights[0][] = 0; |
||
| 65 | $elements[0][] = ['element' => new \XoopsFormPassword(\_MD_SUICO_PASSWORD, 'pass', 35, 32, ''), 'required' => true]; |
||
| 66 | $weights[0][] = 0; |
||
| 67 | $elements[0][] = ['element' => new \XoopsFormPassword(\_US_VERIFYPASS, 'vpass', 35, 32, ''), 'required' => true]; |
||
| 68 | $weights[0][] = 0; |
||
| 69 | } |
||
| 70 | // Dynamic fields |
||
| 71 | $profileHandler = Helper::getInstance()->getHandler('Profile'); |
||
| 72 | $fields = $profileHandler->loadFields(); |
||
| 73 | $_SESSION['profile_required'] = []; |
||
| 74 | foreach (\array_keys($fields) as $i) { |
||
| 75 | if ($fields[$i]->getVar('step_id') == $step['step_id']) { |
||
| 76 | $fieldinfo['element'] = $fields[$i]->getEditElement($user, $profile); |
||
| 77 | //assign and check (=) |
||
| 78 | if ($fieldinfo['required'] = $fields[$i]->getVar('field_required')) { |
||
| 79 | $_SESSION['profile_required'][$fields[$i]->getVar('field_name')] = $fields[$i]->getVar('field_title'); |
||
| 80 | } |
||
| 81 | $key = $fields[$i]->getVar('cat_id'); |
||
| 82 | $elements[$key][] = $fieldinfo; |
||
| 83 | $weights[$key][] = $fields[$i]->getVar('field_weight'); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | \ksort($elements); |
||
| 87 | // Get categories |
||
| 88 | $categoryHandler = \XoopsModules\Suico\Helper::getInstance()->getHandler('Category'); |
||
| 89 | $categories = $categoryHandler->getObjects(null, true, false); |
||
| 90 | foreach (\array_keys($elements) as $k) { |
||
| 91 | \array_multisort($weights[$k], \SORT_ASC, \array_keys($elements[$k]), \SORT_ASC, $elements[$k]); |
||
| 92 | //$title = isset($categories[$k]) ? $categories[$k]['cat_title'] : _MD_SUICO_DEFAULT; |
||
| 93 | //$desc = isset($categories[$k]) ? $categories[$k]['cat_description'] : ""; |
||
| 94 | //$this->insertBreak("<p>{$title}</p>{$desc}"); |
||
| 95 | //$this->addElement(new XoopsFormLabel("<h2>".$title."</h2>", $desc), false); |
||
| 96 | foreach (\array_keys($elements[$k]) as $i) { |
||
| 97 | $this->addElement($elements[$k][$i]['element'], $elements[$k][$i]['required']); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | //end of Dynamic User fields |
||
| 101 | if (1 == $step_no && 0 != $GLOBALS['xoopsConfigUser']['reg_dispdsclmr'] && '' != $GLOBALS['xoopsConfigUser']['reg_disclaimer']) { |
||
| 102 | $disc_tray = new \XoopsFormElementTray(\_US_DISCLAIMER, '<br>'); |
||
| 103 | $disc_text = new \XoopsFormLabel('', '<div class="pad5">' . $GLOBALS['myts']->displayTarea($GLOBALS['xoopsConfigUser']['reg_disclaimer'], 1) . '</div>'); |
||
| 104 | $disc_tray->addElement($disc_text); |
||
| 105 | $agree_chk = new \XoopsFormCheckBox('', 'agree_disc'); |
||
| 106 | $agree_chk->addOption(1, \_US_IAGREE); |
||
| 107 | $disc_tray->addElement($agree_chk); |
||
| 108 | $this->addElement($disc_tray); |
||
| 109 | } |
||
| 110 | global $xoopsModuleConfig; |
||
| 111 | $useCaptchaAfterStep2 = $xoopsModuleConfig['profileCaptchaAfterStep1'] + 1; |
||
| 112 | if ($step_no <= $useCaptchaAfterStep2) { |
||
| 113 | $this->addElement(new \XoopsFormCaptcha(), true); |
||
| 114 | } |
||
| 115 | $this->addElement(new XoopsFormHidden($next_opname, 'register')); |
||
| 116 | $this->addElement(new XoopsFormHidden('uid', $user->getVar('uid'))); |
||
| 117 | $this->addElement(new XoopsFormHidden('step', $step_no)); |
||
| 118 | $this->addElement(new XoopsFormButton('', 'submitButton', \_SUBMIT, 'submit')); |
||
| 119 | } |
||
| 121 |