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