Conditions | 3 |
Paths | 2 |
Total Lines | 53 |
Code Lines | 40 |
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); |
||
91 | public function renderAdminListing(?string $sort = null): string |
||
92 | { |
||
93 | $sort ??= 'id'; |
||
94 | // if (!\class_exists('Xoopsfaq\Utility')) { |
||
95 | // \xoops_load('utility', \basename(\dirname(__DIR__))); |
||
96 | // } |
||
97 | |||
98 | /** @var array $objects */ |
||
99 | $objects = $this->getObj($sort); |
||
100 | |||
101 | $buttons = ['edit', 'delete']; |
||
102 | |||
103 | $ret = '<table class="outer width100 bnone pad3 marg5">' |
||
104 | . ' <thead>' |
||
105 | . ' <tr class="xoopsCenter">' |
||
106 | . ' <th class="width5">' |
||
107 | . \_AM_XOOPSFAQ_CATEGORY_ORDER |
||
108 | . '</th>' |
||
109 | . ' <th class="width5">' |
||
110 | . \_AM_XOOPSFAQ_CATEGORY_ID |
||
111 | . '</th>' |
||
112 | . ' <th class="txtleft">' |
||
113 | . \_AM_XOOPSFAQ_CATEGORY_TITLE |
||
114 | . '</th>' |
||
115 | . ' <th class="width20">' |
||
116 | . \_AM_XOOPSFAQ_ACTIONS |
||
117 | . '</th>' |
||
118 | . ' </tr>' |
||
119 | . ' </thead>' |
||
120 | . ' <tbody>'; |
||
121 | if ($objects['count'] > 0) { |
||
122 | /** @var XoopsObject $object */ |
||
123 | foreach ($objects['list'] as $object) { |
||
124 | $ret .= ' <tr class="xoopsCenter">' |
||
125 | . ' <td class="even txtcenter">' |
||
126 | . $object->getVar('category_order') |
||
127 | . '</td>' |
||
128 | . ' <td class="even txtcenter">' |
||
129 | . $object->getVar('category_id') |
||
130 | . '</td>' |
||
131 | . ' <td class="even txtleft">' |
||
132 | . $object->getVar('category_title') |
||
133 | . '</td>' |
||
134 | . ' <td class="even txtcenter">'; |
||
135 | $ret .= Utility::renderIconLinks($buttons, 'category_id', $object->getVar('category_id')); |
||
136 | $ret .= ' </td>' . ' </tr>'; |
||
137 | } |
||
138 | } else { |
||
139 | $ret .= ' <tr class="txtcenter"><td colspan="4" class="even">' . \_AM_XOOPSFAQ_NOLISTING . '</td></tr>'; |
||
140 | } |
||
141 | $ret .= ' </tbody>' . '</table>'; |
||
142 | |||
143 | return $ret; |
||
144 | } |
||
162 |