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