| Conditions | 8 |
| Paths | 20 |
| Total Lines | 70 |
| Code Lines | 53 |
| 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 |
||
| 114 | public function render($alphaCount = null, $howmanyother = null) |
||
| 115 | { |
||
| 116 | $moduleDirName = \basename(\dirname(__DIR__, 2)); |
||
| 117 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||
| 118 | \xoops_loadLanguage('common', $moduleDirName); |
||
| 119 | \xoops_loadLanguage('alphabet', $moduleDirName); |
||
| 120 | $all = \constant('CO_' . $moduleDirNameUpper . '_ALL'); |
||
| 121 | $other = \constant('CO_' . $moduleDirNameUpper . '_OTHER'); |
||
| 122 | |||
| 123 | $ret = ''; |
||
| 124 | |||
| 125 | if (!$this->caseSensitive) { |
||
| 126 | $this->criteria->setGroupBy('UPPER(LEFT(' . $this->field_name . ',1))'); |
||
| 127 | } else { |
||
| 128 | $this->criteria->setGroupBy('LEFT(' . $this->field_name . ',1)'); |
||
| 129 | } |
||
| 130 | $countsByLetters = $this->objHandler->getCounts($this->criteria); |
||
| 131 | // fill alphabet array |
||
| 132 | $alphabetArray = []; |
||
| 133 | $letter_array = []; |
||
| 134 | |||
| 135 | $letter = 'All'; |
||
| 136 | $letter_array['letter'] = $all; |
||
| 137 | $letter_array['count'] = $alphaCount; |
||
| 138 | $letter_array['url'] = $this->url; |
||
| 139 | $alphabetArray[$letter] = $letter_array; |
||
| 140 | |||
| 141 | foreach ($this->alphabet as $letter) { |
||
| 142 | // $letter_array = []; |
||
| 143 | if (!$this->caseSensitive) { |
||
| 144 | if (isset($countsByLetters[mb_strtoupper($letter)])) { |
||
| 145 | $letter_array['letter'] = $letter; |
||
| 146 | $letter_array['count'] = $countsByLetters[mb_strtoupper($letter)]; |
||
| 147 | $letter_array['url'] = $this->url . '?' . $this->arg_name . '=' . $letter . $this->extra; |
||
| 148 | } else { |
||
| 149 | $letter_array['letter'] = $letter; |
||
| 150 | $letter_array['count'] = 0; |
||
| 151 | $letter_array['url'] = ''; |
||
| 152 | } |
||
| 153 | } elseif (isset($countsByLetters[$letter])) { |
||
| 154 | $letter_array['letter'] = $letter; |
||
| 155 | $letter_array['count'] = $countsByLetters[$letter]; |
||
| 156 | $letter_array['url'] = $this->url . '?' . $this->arg_name . '=' . $letter . $this->extra; |
||
| 157 | } else { |
||
| 158 | $letter_array['letter'] = $letter; |
||
| 159 | $letter_array['count'] = 0; |
||
| 160 | $letter_array['url'] = ''; |
||
| 161 | } |
||
| 162 | $alphabetArray[$letter] = $letter_array; |
||
| 163 | unset($letter_array); |
||
| 164 | } |
||
| 165 | |||
| 166 | $letter_array['letter'] = $other; |
||
| 167 | $letter_array['count'] = $howmanyother; |
||
| 168 | $letter_array['url'] = $this->url . '?init=Other'; |
||
| 169 | $alphabetArray[$letter] = $letter_array; |
||
| 170 | |||
| 171 | // render output |
||
| 172 | if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) { |
||
| 173 | require_once $GLOBALS['xoops']->path('/class/theme.php'); |
||
| 174 | $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
||
| 175 | } |
||
| 176 | require_once $GLOBALS['xoops']->path('/class/template.php'); |
||
| 177 | $choiceByLetterTpl = new \XoopsTpl(); |
||
| 178 | $choiceByLetterTpl->caching = 0; // Disable cache |
||
| 179 | $choiceByLetterTpl->assign('alphabet', $alphabetArray); |
||
| 180 | $ret .= $choiceByLetterTpl->fetch("db:{$this->helper->getDirname()}_letterschoice.tpl"); |
||
| 181 | unset($choiceByLetterTpl); |
||
| 182 | |||
| 183 | return $ret; |
||
| 184 | } |
||
| 186 |