Conditions | 4 |
Paths | 2 |
Total Lines | 61 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
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 |
||
12 | function b_instr_lastpage_show($options = []) |
||
13 | { |
||
14 | |||
15 | // Подключаем функции |
||
16 | $moduleDirName = basename(dirname(__DIR__)); |
||
17 | include_once $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/class/utility.php'); |
||
18 | // |
||
19 | $myts = MyTextSanitizer::getInstance(); |
||
20 | // |
||
21 | //mb $instructionHandler = xoops_getModuleHandler('instruction', 'instruction'); |
||
|
|||
22 | //mb $pageHandler = xoops_getModuleHandler('page', 'instruction'); |
||
23 | |||
24 | $db = \XoopsDatabaseFactory::getDatabase(); |
||
25 | $instructionHandler = new \Xoopsmodules\instruction\InstructionHandler($db); |
||
26 | $pageHandler = new \Xoopsmodules\instruction\PageHandler($db); |
||
27 | |||
28 | // Добавляем стили |
||
29 | //global $xoTheme; |
||
30 | //$xoTheme->addStylesheet( XOOPS_URL . '/modules/instruction/css/blocks.css' ); |
||
31 | |||
32 | // Опции |
||
33 | // Количество страниц |
||
34 | $limit = $options[0]; |
||
35 | // Количество символов |
||
36 | $numchars = $options[1]; |
||
37 | |||
38 | // Права на просмотр |
||
39 | $cat_view = Xoopsmodules\instruction\Utility::getItemIds(); |
||
40 | // Массив выходных данных |
||
41 | $block = []; |
||
42 | |||
43 | // Если есть категории для прасмотра |
||
44 | if (is_array($cat_view) && count($cat_view) > 0) { |
||
45 | |||
46 | // Находим последние страницы |
||
47 | $sql = "SELECT p.pageid, p.instrid, p.title, p.dateupdated, i.title, i.cid FROM {$pageHandler->table} p, {$instructionHandler->table} i WHERE p.instrid = i.instrid AND i.cid IN (" . implode(', ', $cat_view) . ') AND p.status > 0 AND i.status > 0 ORDER BY p.dateupdated DESC'; |
||
48 | // Лимит запроса |
||
49 | $result = $GLOBALS['xoopsDB']->query($sql, $limit); |
||
50 | // Перебираем все значения |
||
51 | $i = 0; |
||
52 | while (list($pageid, $instrid, $ptitle, $dateupdated, $ititle, $cid) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
||
53 | // ID страницы |
||
54 | $block[$i]['pageid'] = $pageid; |
||
55 | // ID инструкции |
||
56 | $block[$i]['instrid'] = $instrid; |
||
57 | // Название страницы |
||
58 | $block[$i]['ptitle'] = $myts->htmlSpecialChars($ptitle); |
||
59 | // Название инструкции |
||
60 | $block[$i]['ititle'] = $myts->htmlSpecialChars($ititle); |
||
61 | // Дата обновления страницы |
||
62 | $block[$i]['dateupdated'] = formatTimeStamp($dateupdated, 's'); |
||
63 | // Категория инстркции |
||
64 | $block[$i]['cid'] = $cid; |
||
65 | // Инкримент |
||
66 | $i++; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | // Возвращаем массив |
||
71 | return $block; |
||
72 | } |
||
73 | |||
88 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.