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