Conditions | 8 |
Paths | 20 |
Total Lines | 73 |
Code Lines | 55 |
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 |
||
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 | |||
131 | $countsByLetters = $this->objHandler->getCounts($this->criteria); |
||
132 | // fill alphabet array |
||
133 | $alphabetArray = []; |
||
134 | $letter_array = []; |
||
135 | |||
136 | $letter = 'All'; |
||
137 | $letter_array['letter'] = $all; |
||
138 | $letter_array['count'] = $alphaCount; |
||
139 | $letter_array['url'] = $this->url; |
||
140 | $alphabetArray[$letter] = $letter_array; |
||
141 | |||
142 | foreach ($this->alphabet as $letter) { |
||
143 | $letter_array = []; |
||
144 | if (!$this->caseSensitive) { |
||
145 | if (isset($countsByLetters[mb_strtoupper($letter)])) { |
||
146 | $letter_array['letter'] = $letter; |
||
147 | $letter_array['count'] = $countsByLetters[mb_strtoupper($letter)]; |
||
148 | $letter_array['url'] = $this->url . '?' . $this->arg_name . '=' . $letter . $this->extra; |
||
149 | } else { |
||
150 | $letter_array['letter'] = $letter; |
||
151 | $letter_array['count'] = 0; |
||
152 | $letter_array['url'] = ''; |
||
153 | } |
||
154 | } else { |
||
155 | if (isset($countsByLetters[$letter])) { |
||
156 | $letter_array['letter'] = $letter; |
||
157 | $letter_array['count'] = $countsByLetters[$letter]; |
||
158 | $letter_array['url'] = $this->url . '?' . $this->arg_name . '=' . $letter . $this->extra; |
||
159 | } else { |
||
160 | $letter_array['letter'] = $letter; |
||
161 | $letter_array['count'] = 0; |
||
162 | $letter_array['url'] = ''; |
||
163 | } |
||
164 | } |
||
165 | $alphabetArray[$letter] = $letter_array; |
||
166 | unset($letter_array); |
||
167 | } |
||
168 | |||
169 | $letter_array['letter'] = $other; |
||
170 | $letter_array['count'] = $howmanyother; |
||
171 | $letter_array['url'] = $this->url . '?init=Other'; |
||
172 | $alphabetArray[$letter] = $letter_array; |
||
173 | |||
174 | // render output |
||
175 | if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) { |
||
176 | require_once $GLOBALS['xoops']->path('/class/theme.php'); |
||
177 | $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
||
178 | } |
||
179 | require_once $GLOBALS['xoops']->path('/class/template.php'); |
||
180 | $choiceByLetterTpl = new \XoopsTpl(); |
||
181 | $choiceByLetterTpl->caching = false; // Disable cache |
||
182 | $choiceByLetterTpl->assign('alphabet', $alphabetArray); |
||
183 | $ret .= $choiceByLetterTpl->fetch("db:{$this->helper->getDirname()}_letterschoice.tpl"); |
||
184 | unset($choiceByLetterTpl); |
||
185 | |||
186 | return $ret; |
||
187 | } |
||
189 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.