Conditions | 5 |
Paths | 2 |
Total Lines | 94 |
Code Lines | 81 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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); |
||
149 | public function renderAdminListing($sort = null): string |
||
150 | { |
||
151 | $sort ??= 'id'; |
||
152 | // if (!\class_exists('Xoopsfaq\Utility')) { |
||
153 | // \xoops_load('utility', \basename(\dirname(__DIR__))); |
||
154 | // } |
||
155 | |||
156 | /** @var CategoryHandler $categoryHandler */ |
||
157 | $objects = $this->getObj($sort); |
||
158 | $helper = Helper::getHelper(\basename(\dirname(__DIR__))); |
||
159 | $categoryHandler = $helper->getHandler('Category'); |
||
160 | $catFields = ['category_id', 'category_title']; |
||
161 | $catArray = $categoryHandler->getAll(null, $catFields, false); |
||
162 | |||
163 | $buttons = ['edit', 'delete']; |
||
164 | |||
165 | $ret = '<table class="outer width100 bnone pad3 marg5">' |
||
166 | . ' <thead>' |
||
167 | . ' <tr class="center">' |
||
168 | . ' <th class="width5">' |
||
169 | . \_AM_XOOPSFAQ_CONTENTS_ID |
||
170 | . '</th>' |
||
171 | . ' <th class="width5">' |
||
172 | . \_AM_XOOPSFAQ_CONTENTS_ACTIVE |
||
173 | . '</th>' |
||
174 | . ' <th class="width5">' |
||
175 | . \_AM_XOOPSFAQ_CONTENTS_WEIGHT |
||
176 | . '</th>' |
||
177 | . ' <th class="left">' |
||
178 | . \_AM_XOOPSFAQ_CONTENTS_TITLE |
||
179 | . '</th>' |
||
180 | . ' <th class="left">' |
||
181 | . \_AM_XOOPSFAQ_CATEGORY_TITLE |
||
182 | . '</th>' |
||
183 | . ' <th>' |
||
184 | . \_AM_XOOPSFAQ_CONTENTS_PUBLISH |
||
185 | . '</th>' |
||
186 | . ' <th class="width20">' |
||
187 | . \_AM_XOOPSFAQ_ACTIONS |
||
188 | . '</th>' |
||
189 | . ' </tr>' |
||
190 | . ' </thead>' |
||
191 | . ' <tbody>'; |
||
192 | if (\is_array($objects) && ($objects['count'] > 0)) { |
||
193 | $tdClass = 0; |
||
194 | /** @var \Contents $object */ |
||
195 | foreach ($objects['list'] as $object) { |
||
196 | $thisCatId = $object->getVar('contents_cid'); |
||
197 | $thisCatTitle = $catArray[$thisCatId]['category_title']; |
||
198 | $thisContentTitle = '<a href="' . $helper->url('index.php?cat_id=' . $thisCatId . '#q' . $object->getVar('contents_id')) . '" title="' . \_AM_XOOPSFAQ_CONTENTS_VIEW . '">' . $object->getVar('contents_title') . '</a>'; |
||
199 | ++$tdClass; |
||
200 | $dispClass = ($tdClass % 1) ? 'even' : 'odd'; |
||
201 | $ret .= ' <tr class="center middle">' |
||
202 | . ' <td class="' |
||
203 | . $dispClass |
||
204 | . '">' |
||
205 | . $object->getVar('contents_id') |
||
206 | . '</td>' |
||
207 | . ' <td class="' |
||
208 | . $dispClass |
||
209 | . '">' |
||
210 | . $object->getActiveIcon() |
||
211 | . '</td>' |
||
212 | . ' <td class="' |
||
213 | . $dispClass |
||
214 | . '">' |
||
215 | . $object->getVar('contents_weight') |
||
216 | . '</td>' |
||
217 | . ' <td class="' |
||
218 | . $dispClass |
||
219 | . ' left">' |
||
220 | . $thisContentTitle |
||
221 | . '</td>' |
||
222 | . ' <td class="' |
||
223 | . $dispClass |
||
224 | . ' left">' |
||
225 | . $thisCatTitle |
||
226 | . '</td>' |
||
227 | . ' <td class="' |
||
228 | . $dispClass |
||
229 | . '">' |
||
230 | . $object->getPublished(\_SHORTDATESTRING) |
||
231 | . '</td>' |
||
232 | . ' <td class="' |
||
233 | . $dispClass |
||
234 | . '">'; |
||
235 | $ret .= Utility::renderIconLinks($buttons, 'contents_id', $object->getVar('contents_id')) . '</td>' . ' </tr>'; |
||
236 | } |
||
237 | } else { |
||
238 | $ret .= ' <tr class="center"><td colspan="7" class="even">' . \_AM_XOOPSFAQ_NOLISTING . '</td></tr>'; |
||
239 | } |
||
240 | $ret .= ' </tbody>' . '</table>'; |
||
241 | |||
242 | return $ret; |
||
243 | } |
||
263 |