| Conditions | 28 |
| Paths | 336 |
| Total Lines | 99 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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); |
||
| 115 | public function getEditElement($user, $profile) |
||
| 116 | { |
||
| 117 | $value = \in_array($this->getVar('field_name'), $this->getUserVars(), true) ? $user->getVar($this->getVar('field_name'), 'e') : $profile->getVar($this->getVar('field_name'), 'e'); |
||
| 118 | $caption = $this->getVar('field_title'); |
||
| 119 | $caption = \defined($caption) ? \constant($caption) : $caption; |
||
| 120 | $name = $this->getVar('field_name', 'e'); |
||
| 121 | $options = $this->getVar('field_options'); |
||
| 122 | if (\is_array($options)) { |
||
| 123 | //asort($options); |
||
| 124 | foreach (\array_keys($options) as $key) { |
||
| 125 | $optval = \defined($options[$key]) ? \constant($options[$key]) : $options[$key]; |
||
| 126 | $optkey = \defined((string)$key) ? \constant($key) : $key; |
||
| 127 | unset($options[$key]); |
||
| 128 | $options[$optkey] = $optval; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
||
| 132 | switch ($this->getVar('field_type')) { |
||
| 133 | default: |
||
| 134 | case 'autotext': |
||
| 135 | //autotext is not for editing |
||
| 136 | $element = new \XoopsFormLabel($caption, $this->getOutputValue($user, $profile)); |
||
| 137 | break; |
||
| 138 | case 'textbox': |
||
| 139 | $element = new \XoopsFormText($caption, $name, 35, $this->getVar('field_maxlength'), $value); |
||
| 140 | break; |
||
| 141 | case 'textarea': |
||
| 142 | $element = new \XoopsFormTextArea($caption, $name, $value, 4, 30); |
||
| 143 | break; |
||
| 144 | case 'dhtml': |
||
| 145 | $element = new \XoopsFormDhtmlTextArea($caption, $name, $value, 10, 30); |
||
| 146 | break; |
||
| 147 | case 'select': |
||
| 148 | $element = new \XoopsFormSelect($caption, $name, $value); |
||
| 149 | // If options do not include an empty element, then add a blank option to prevent any default selection |
||
| 150 | // if (!in_array('', array_keys($options))) { |
||
| 151 | if (!\array_key_exists('', $options)) { |
||
| 152 | $element->addOption('', \_NONE); |
||
| 153 | $eltmsg = empty($caption) ? \sprintf(\_FORM_ENTER, $name) : \sprintf(\_FORM_ENTER, $caption); |
||
| 154 | $eltmsg = \str_replace('"', '\"', \stripslashes($eltmsg)); |
||
| 155 | $element->customValidationCode[] = "\nvar hasSelected = false; var selectBox = myform.{$name};" |
||
| 156 | . "for (i = 0; i < selectBox.options.length; i++) { if (selectBox.options[i].selected === true && selectBox.options[i].value != '') { hasSelected = true; break; } }" |
||
| 157 | . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }"; |
||
| 158 | } |
||
| 159 | $element->addOptionArray($options); |
||
| 160 | break; |
||
| 161 | case 'select_multi': |
||
| 162 | $element = new \XoopsFormSelect($caption, $name, $value, 5, true); |
||
| 163 | $element->addOptionArray($options); |
||
| 164 | break; |
||
| 165 | case 'radio': |
||
| 166 | $element = new \XoopsFormRadio($caption, $name, $value); |
||
| 167 | $element->addOptionArray($options); |
||
| 168 | break; |
||
| 169 | case 'checkbox': |
||
| 170 | $element = new \XoopsFormCheckBox($caption, $name, $value); |
||
| 171 | $element->addOptionArray($options); |
||
| 172 | break; |
||
| 173 | case 'yesno': |
||
| 174 | $element = new \XoopsFormRadioYN($caption, $name, $value); |
||
| 175 | break; |
||
| 176 | case 'group': |
||
| 177 | $element = new \XoopsFormSelectGroup($caption, $name, true, $value); |
||
| 178 | break; |
||
| 179 | case 'group_multi': |
||
| 180 | $element = new \XoopsFormSelectGroup($caption, $name, true, $value, 5, true); |
||
| 181 | break; |
||
| 182 | case 'language': |
||
| 183 | $element = new \XoopsFormSelectLang($caption, $name, $value); |
||
| 184 | break; |
||
| 185 | case 'date': |
||
| 186 | $element = new \XoopsFormTextDateSelect($caption, $name, 15, $value); |
||
| 187 | break; |
||
| 188 | case 'longdate': |
||
| 189 | $element = new \XoopsFormTextDateSelect($caption, $name, 15, \str_replace('-', '/', $value)); |
||
| 190 | break; |
||
| 191 | case 'datetime': |
||
| 192 | $element = new \XoopsFormDatetime($caption, $name, 15, $value); |
||
| 193 | break; |
||
| 194 | case 'timezone': |
||
| 195 | $element = new \XoopsFormSelectTimezone($caption, $name, $value); |
||
| 196 | $element->setExtra("style='width: 280px;'"); |
||
| 197 | break; |
||
| 198 | case 'rank': |
||
| 199 | $element = new \XoopsFormSelect($caption, $name, $value); |
||
| 200 | require_once $GLOBALS['xoops']->path('class/xoopslists.php'); |
||
| 201 | $ranks = \XoopsLists::getUserRankList(); |
||
| 202 | $element->addOption(0, '--------------'); |
||
| 203 | $element->addOptionArray($ranks); |
||
| 204 | break; |
||
| 205 | case 'theme': |
||
| 206 | $element = new \XoopsFormSelectTheme($caption, $name, $value, 1, true); |
||
| 207 | break; |
||
| 208 | } |
||
| 209 | if ('' != $this->getVar('field_description')) { |
||
| 210 | $element->setDescription($this->getVar('field_description')); |
||
| 211 | } |
||
| 212 | |||
| 213 | return $element; |
||
| 214 | } |
||
| 392 |