Conditions | 15 |
Paths | 2560 |
Total Lines | 122 |
Code Lines | 88 |
Lines | 22 |
Ratio | 18.03 % |
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 |
||
151 | function AdsModCat($cid) |
||
152 | { |
||
153 | global $xoopsDB, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $myts, $moduleDirName; |
||
1 ignored issue
–
show
|
|||
154 | |||
155 | $mytree = new ClassifiedsTree($xoopsDB->prefix('adslight_categories'), 'cid', 'pid'); |
||
156 | |||
157 | include_once __DIR__ . '/header.php'; |
||
158 | |||
159 | // loadModuleAdminMenu(1, ""); |
||
160 | echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_ADSLIGHT_MODIFCAT . '</legend>'; |
||
161 | ShowImg(); |
||
162 | |||
163 | $result = $xoopsDB->query('SELECT cid, pid, title, cat_desc, cat_keywords, img, ordre, affprice, cat_moderate, moderate_subcat FROM ' |
||
164 | . $xoopsDB->prefix('adslight_categories') |
||
165 | . " WHERE cid=$cid"); |
||
166 | list($cat_id, $pid, $title, $cat_desc, $cat_keywords, $imgs, $ordre, $affprice, $cat_moderate, $moderate_subcat) = $xoopsDB->fetchRow($result); |
||
167 | |||
168 | $title = $myts->htmlSpecialChars($title); |
||
169 | $cat_desc = $myts->addSlashes($cat_desc); |
||
170 | echo "<form action=\"category.php\" method=\"post\" name=\"imcat\"> |
||
171 | <table class=\"outer\" border=\"0\"><tr> |
||
172 | <td class=\"even\">" |
||
173 | . _AM_ADSLIGHT_CATNAME |
||
174 | . " </td><td class=\"odd\"><input type=\"text\" name=\"title\" value=\"$title\" size=\"50\" maxlength=\"100\" /> " |
||
175 | . _AM_ADSLIGHT_IN |
||
176 | . ' '; |
||
177 | $mytree->makeMySelBox('title', 'title', $pid, 1); |
||
178 | echo '</td></tr>'; |
||
179 | |||
180 | View Code Duplication | if ($xoopsModuleConfig['adslight_cat_desc'] = '1') { |
|
1 ignored issue
–
show
|
|||
181 | echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_CAT_META_DESCRIPTION . " </td><td class=\"odd\" colspan=2>"; |
||
182 | echo "<input type=\"text\" name=\"cat_desc\" value=\"$cat_desc\" size=\"80\" maxlength=\"200\">"; |
||
183 | echo '</td></tr>'; |
||
184 | |||
185 | echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_CAT_META_KEYWORDS . " </td><td class=\"odd\" colspan=2>"; |
||
186 | echo "<input type=\"text\" name=\"cat_keywords\" value=\"$cat_keywords\" size=\"80\" maxlength=\"200\">"; |
||
187 | echo '</td></tr>'; |
||
188 | } |
||
189 | |||
190 | echo "<tr> |
||
191 | <td class=\"even\">" . _AM_ADSLIGHT_IMGCAT . " </td><td class=\"odd\"><select name=\"img\" onChange=\"showimage()\">"; |
||
192 | |||
193 | $rep = XOOPS_ROOT_PATH . '/modules/adslight/assets/images/img_cat'; |
||
194 | $handle = opendir($rep); |
||
195 | while ($file = readdir($handle)) { |
||
196 | $filelist[] = $file; |
||
197 | } |
||
198 | asort($filelist); |
||
199 | View Code Duplication | while (list($key, $file) = each($filelist)) { |
|
1 ignored issue
–
show
|
|||
200 | if (!preg_match('`gif$|jpg$|png$`i', $file)) { |
||
201 | if ($file === '.' || $file === '..') { |
||
202 | $a = 1; |
||
203 | } |
||
204 | } else { |
||
205 | if ($file == $imgs) { |
||
206 | echo "<option value=$file selected>$file</option>"; |
||
207 | } else { |
||
208 | echo "<option value=$file>$file</option>"; |
||
209 | } |
||
210 | } |
||
211 | } |
||
212 | echo "</select> <img src=\"" |
||
213 | . XOOPS_URL |
||
214 | . "/modules/adslight/assets/images/img_cat/$imgs\" name=\"avatar\" align=\"absmiddle\"><br><b>" |
||
215 | . _AM_ADSLIGHT_REPIMGCAT |
||
216 | . '</b><br>../modules/adslight/assets/images/img_cat/..</td></tr>'; |
||
217 | |||
218 | echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_DISPLPRICE2 . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"affprice\" value=\"1\""; |
||
219 | if ($affprice == '1') { |
||
220 | echo 'checked'; |
||
221 | } |
||
222 | echo '>' . _AM_ADSLIGHT_OUI . " <input type=\"radio\" name=\"affprice\" value=\"0\""; |
||
223 | if ($affprice == '0') { |
||
224 | echo 'checked'; |
||
225 | } |
||
226 | echo '>' . _AM_ADSLIGHT_NON . ' (' . _AM_ADSLIGHT_INTHISCAT . ')</td></tr>'; |
||
227 | |||
228 | echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_MODERATE_CAT . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"cat_moderate\" value=\"1\""; |
||
229 | if ($cat_moderate == '1') { |
||
230 | echo 'checked'; |
||
231 | } |
||
232 | echo '>' . _AM_ADSLIGHT_OUI . " <input type=\"radio\" name=\"cat_moderate\" value=\"0\""; |
||
233 | if ($cat_moderate == '0') { |
||
234 | echo 'checked'; |
||
235 | } |
||
236 | echo '>' . _AM_ADSLIGHT_NON . '</td></tr>'; |
||
237 | |||
238 | echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_MODERATE_SUBCATS . " </td><td class=\"odd\" colspan=2><input type=\"radio\" name=\"moderate_subcat\" value=\"1\""; |
||
239 | if ($moderate_subcat == '1') { |
||
240 | echo 'checked'; |
||
241 | } |
||
242 | echo '>' . _AM_ADSLIGHT_OUI . " <input type=\"radio\" name=\"moderate_subcat\" value=\"0\""; |
||
243 | if ($moderate_subcat == '0') { |
||
244 | echo 'checked'; |
||
245 | } |
||
246 | echo '>' . _AM_ADSLIGHT_NON . '</td></tr>'; |
||
247 | |||
248 | if ($xoopsModuleConfig['adslight_csortorder'] !== 'title') { |
||
249 | echo "<tr><td class=\"even\">" . _AM_ADSLIGHT_ORDRE . " </td><td class=\"odd\"><input type=\"text\" name=\"ordre\" size=\"4\" value=\"$ordre\"></td></tr>"; |
||
250 | } else { |
||
251 | $ordre = (int)$ordre; |
||
252 | echo "<input type=\"hidden\" name=\"ordre\" value=\"$ordre\">"; |
||
253 | } |
||
254 | |||
255 | echo '</table>'; |
||
256 | |||
257 | echo "<input type=\"hidden\" name=\"cidd\" value=\"$cid\">" |
||
258 | . "<input type=\"hidden\" name=\"op\" value=\"AdsModCatS\">" |
||
259 | . "<table class=\"foot\" border=\"0\"><tr><td width=\"20%\"><br>" |
||
260 | |||
261 | . "<input type=\"submit\" value=\"" |
||
262 | . _AM_ADSLIGHT_SAVMOD |
||
263 | . "\"></form></td><td><br>" |
||
264 | . "<form action=\"category.php\" method=\"post\">" |
||
265 | . "<input type=\"hidden\" name=\"cid\" value=\"$cid\">" |
||
266 | . "<input type=\"hidden\" name=\"op\" value=\"AdsDelCat\">" |
||
267 | . "<input type=\"submit\" value=\"" |
||
268 | . _AM_ADSLIGHT_DEL |
||
269 | . "\"></form></td></tr></table>"; |
||
270 | echo '</fieldset><br>'; |
||
271 | xoops_cp_footer(); |
||
272 | } |
||
273 | |||
419 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.