instr_lastinstr.php ➔ b_instr_lastinstr_show()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 57
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 22
nc 2
nop 1
dl 0
loc 57
rs 9.0309
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
/**
10
 * @param array $options
11
 * @return array
12
 */
13
function b_instr_lastinstr_show($options = [])
14
{
15
16
    // Подключаем функции
17
    //    $moduleDirName = dirname(__DIR__);
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...
18
    $moduleDirName = basename(dirname(__DIR__));
19
    //    include_once $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/class/utility.php');
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
20
    include_once $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/common.php');
21
    //
22
    $myts = MyTextSanitizer::getInstance();
23
    //
24
    //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...
25
    $db                 = \XoopsDatabaseFactory::getDatabase();
26
    $instructionHandler = new \Xoopsmodules\instruction\InstructionHandler($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 `instrid`, `cid`, `title`, `pages`, `dateupdated` FROM {$instructionHandler->table} WHERE `cid` IN (" . implode(', ', $cat_view) . ') AND `status` > 0 ORDER BY `dateupdated` DESC';
48
        // Лимит запроса
49
        $result = $GLOBALS['xoopsDB']->query($sql, $limit);
50
        // Перебираем все значения
51
        $i = 0;
52
        while (list($instrid, $cid, $ititle, $pages, $dateupdated) = $GLOBALS['xoopsDB']->fetchRow($result)) {
53
            // ID инструкции
54
            $block[$i]['instrid'] = $instrid;
55
            // ID категории
56
            $block[$i]['cid'] = $cid;
57
            // Название инструкции
58
            $block[$i]['ititle'] = $myts->htmlSpecialChars($ititle);
59
            // Число страниц
60
            $block[$i]['pages'] = $pages;
61
            // Дата обновления инструкции
62
            $block[$i]['dateupdated'] = formatTimeStamp($dateupdated, 's');
63
            // Инкримент
64
            $i++;
65
        }
66
    }
67
    // Возвращаем массив
68
    return $block;
69
}
70
71
// Редактирование последних инструкций
72
/**
73
 * @param array $options
74
 * @return string
75
 */
76 View Code Duplication
function b_instr_lastinstr_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...
77
{
78
    $form = '';
79
    $form .= _MB_INSTR_DISPLAYINSTRC . ' <input name="options[0]" size="5" maxlength="255" value="' . $options[0] . '" type="text" ><br>' . "\n";
80
    $form .= _MB_INSTR_NUMCHARSC . ' <input name="options[1]" size="5" maxlength="255" value="' . $options[1] . '" type="text" ><br>' . "\n";
81
82
    // Возвращаем форму
83
    return $form;
84
}
85