Completed
Push — master ( a4e09c...825da9 )
by Michael
01:51
created

instr_lastpage.php ➔ b_instr_lastpage_show()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 61
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 24
nc 2
nop 1
dl 0
loc 61
rs 8.9392
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
use Xoopsmodules\instruction;
4
5
// Блоки модуля инструкций
6
7
// Последние страницы
8
/**
9
 * @param array $options
10
 * @return array
11
 */
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');
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
22
    //mb    $pageHandler  = xoops_getModuleHandler('page', 'instruction');
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
31
32
    // Опции
33
    // Количество страниц
34
    $limit = $options[0];
35
    // Количество символов
36
    $numchars = $options[1];
0 ignored issues
show
Unused Code introduced by
$numchars is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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
74
// Редактирование последних страниц
75
/**
76
 * @param array $options
77
 * @return string
78
 */
79 View Code Duplication
function b_instr_lastpage_edit($options = [])
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
{
81
    $form = '';
82
    $form .= _MB_INSTR_DISPLAYPAGESC . ' <input name="options[0]" size="5" maxlength="255" value="' . $options[0] . '" type="text" /><br>' . "\n";
83
    $form .= _MB_INSTR_NUMCHARSC . ' <input name="options[1]" size="5" maxlength="255" value="' . $options[1] . '" type="text" /><br>' . "\n";
84
85
    // Возвращаем форму
86
    return $form;
87
}
88