| Conditions | 10 |
| Paths | 48 |
| Total Lines | 58 |
| Code Lines | 49 |
| 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 |
||
| 152 | public function render() |
||
| 153 | { |
||
| 154 | global $xoopsUser; |
||
| 155 | if (!is_object($xoopsUser)) { |
||
| 156 | $group = [XOOPS_GROUP_ANONYMOUS]; |
||
| 157 | } else { |
||
| 158 | $group = &$xoopsUser->getGroups(); |
||
| 159 | } |
||
| 160 | $imgcatHandler = xoops_getHandler('imagecategory'); |
||
| 161 | $catlist = $imgcatHandler->getList($group, 'imgcat_write', 1); |
||
| 162 | $catlist_total = count($catlist); |
||
| 163 | $optIds = $this->getOptGroupsID(); |
||
| 164 | $ret = "<select onchange='if(this.options[this.selectedIndex].value != \"\"){ document.getElementById(\"" |
||
| 165 | . $this->getName() |
||
| 166 | . '_img").src="' |
||
| 167 | . XOOPS_URL |
||
| 168 | . '"+this.options[this.selectedIndex].value;} else {document.getElementById("' |
||
| 169 | . $this->getName() |
||
| 170 | . '_img").src="' |
||
| 171 | . XOOPS_URL |
||
| 172 | . '/modules/' |
||
| 173 | . MGO_MOD_DIR |
||
| 174 | . "/assets/images/spager.gif\";}' size='" |
||
| 175 | . $this->getSize() |
||
| 176 | . "'" |
||
| 177 | . $this->getExtra() |
||
| 178 | . ''; |
||
| 179 | if (false !== $this->isMultiple()) { |
||
| 180 | $ret .= " name='" . $this->getName() . "[]' id='" . $this->getName() . "[]' multiple='multiple'>\n"; |
||
| 181 | } else { |
||
| 182 | $ret .= " name='" . $this->getName() . "' id='" . $this->getName() . "'>\n"; |
||
| 183 | } |
||
| 184 | $ret .= "<option value=''>" . _SELECT . "</option>\n"; |
||
| 185 | foreach ($this->getOptGroups() as $nome => $valores) { |
||
| 186 | $ret .= '\n<optgroup id="img_cat_' . $optIds[$nome] . '" label="' . $nome . '">'; |
||
| 187 | if (is_array($valores)) { |
||
| 188 | foreach ($valores as $value => $name) { |
||
| 189 | $ret .= "<option value='" . htmlspecialchars($value, ENT_QUOTES) . "'"; |
||
| 190 | if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) { |
||
| 191 | $ret .= ' selected'; |
||
| 192 | $imagem = $value; |
||
| 193 | } |
||
| 194 | $ret .= '>' . $name . "</option>\n"; |
||
| 195 | } |
||
| 196 | } |
||
| 197 | $ret .= '</optgroup>\n'; |
||
| 198 | } |
||
| 199 | $browse_url = __DIR__ . '/formimage_browse.php'; |
||
| 200 | $browse_url = str_replace(XOOPS_ROOT_PATH, XOOPS_URL, $browse_url); |
||
| 201 | $ret .= '</select>'; |
||
| 202 | $ret .= ($catlist_total > 0) ? " <input type='button' value='" |
||
| 203 | . _ADDIMAGE |
||
| 204 | . "' onclick=\"window.open('$browse_url?target=" |
||
| 205 | . $this->getName() |
||
| 206 | . "','MastopFormImage','resizable=yes,width=500,height=470,left='+(screen.availWidth/2-200)+',top='+(screen.availHeight/2-200)+'');return false;\">" : ''; |
||
| 207 | $ret .= "<br><img id='" . $this->getName() . "_img' src='" . (!empty($imagem) ? XOOPS_URL . $imagem : XOOPS_URL . '/modules/' . MGO_MOD_DIR . '/assets/images/spacer.gif') . "'>"; |
||
| 208 | |||
| 209 | return $ret; |
||
| 210 | } |
||
| 212 |