| Conditions | 17 |
| Paths | 17 |
| Total Lines | 78 |
| Code Lines | 73 |
| 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); |
||
| 109 | public function render() |
||
| 110 | { |
||
| 111 | switch ($this->type) { |
||
| 112 | case Constants::FIELD_LABEL: |
||
| 113 | $field = new \XoopsFormLabel($this->caption, $this->value); |
||
| 114 | break; |
||
| 115 | case Constants::FIELD_TEXTBOX: |
||
| 116 | case Constants::FIELD_NAME: |
||
| 117 | case Constants::FIELD_EMAIL: |
||
| 118 | $field = new \XoopsFormText($this->caption, $this->name, $this->size, $this->maxlength, $this->value); |
||
| 119 | $field->setExtra('placeholder="' . $this->placeholder . '"'); |
||
| 120 | $field->setDescription($this->desc); |
||
| 121 | break; |
||
| 122 | case Constants::FIELD_TEXTAREA: |
||
| 123 | $field = new \XoopsFormTextArea($this->caption, $this->name, $this->value, $this->rows, $this->cols); |
||
| 124 | $field->setDescription($this->desc); |
||
| 125 | break; |
||
| 126 | case Constants::FIELD_TEXTEDITOR: |
||
| 127 | $editorConfigs = []; |
||
| 128 | $helper = Helper::getInstance(); |
||
| 129 | $editor = $helper->getConfig('editor_user'); |
||
| 130 | $editorConfigs['name'] = $this->name; |
||
| 131 | $editorConfigs['value'] = $this->value; |
||
| 132 | $editorConfigs['rows'] = $this->rows; |
||
| 133 | $editorConfigs['cols'] = $this->cols; |
||
| 134 | $editorConfigs['width'] = '100%'; |
||
| 135 | $editorConfigs['height'] = '400px'; |
||
| 136 | $editorConfigs['editor'] = $editor; |
||
| 137 | $field = new \XoopsFormEditor($this->caption, $this->name, $editorConfigs); |
||
| 138 | $field->setDescription($this->desc); |
||
| 139 | break; |
||
| 140 | case Constants::FIELD_RADIO: |
||
| 141 | $field = new \XoopsFormRadio($this->caption, $this->name, $this->value); |
||
| 142 | $field->addOptionArray($this->optionsArr); |
||
| 143 | $field->setDescription($this->desc); |
||
| 144 | break; |
||
| 145 | case Constants::FIELD_RADIOYN: |
||
| 146 | $field = new \XoopsFormRadioYN($this->caption, $this->name, $this->value); |
||
| 147 | $field->setDescription($this->desc); |
||
| 148 | break; |
||
| 149 | case Constants::FIELD_SELECTBOX: |
||
| 150 | $field = new \XoopsFormSelect($this->caption, $this->name, $this->value); |
||
| 151 | $field->addOptionArray($this->optionsArr); |
||
| 152 | $field->setDescription($this->desc); |
||
| 153 | break; |
||
| 154 | case Constants::FIELD_COMBOBOX: |
||
| 155 | $field = new \XoopsFormSelect($this->caption, $this->name, $this->value, 5, true); |
||
| 156 | $field->addOptionArray($this->optionsArr); |
||
| 157 | $field->setDescription($this->desc); |
||
| 158 | break; |
||
| 159 | case Constants::FIELD_DATE: |
||
| 160 | $field = new \XoopsFormTextDateSelect($this->caption, $this->name, '', $this->value); |
||
|
|
|||
| 161 | $field->setDescription($this->desc); |
||
| 162 | break; |
||
| 163 | case Constants::FIELD_DATETIME: |
||
| 164 | $field = new \XoopsFormDateTime($this->caption, $this->name, '', $this->value); |
||
| 165 | $field->setDescription($this->desc); |
||
| 166 | break; |
||
| 167 | case Constants::FIELD_CHECKBOX: |
||
| 168 | $field = new \XoopsFormCheckBox($this->caption, $this->name, $this->value); |
||
| 169 | if (\count($this->optionsArr) > 0) { |
||
| 170 | $field->addOptionArray($this->optionsArr); |
||
| 171 | } else { |
||
| 172 | $field->addOption(1, $this->optionsText); |
||
| 173 | } |
||
| 174 | $field->setDescription($this->desc); |
||
| 175 | break; |
||
| 176 | case Constants::FIELD_COUNTRY: |
||
| 177 | $field = new \XoopsFormSelectCountry($this->caption, $this->name, $this->value); |
||
| 178 | $field->setDescription($this->desc); |
||
| 179 | break; |
||
| 180 | case 0: |
||
| 181 | default: |
||
| 182 | echo 'Error: invalid type in Formelementshandler/render'; |
||
| 183 | die; |
||
| 184 | } |
||
| 185 | |||
| 186 | return $field; |
||
| 187 | } |
||
| 215 |