Passed
Push — master ( 3a2152...658ebb )
by Goffy
04:30 queued 12s
created

b_scrolling_term_edit()   F

Complexity

Conditions 21
Paths > 20000

Size

Total Lines 60
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 21
eloc 47
nc 655360
nop 1
dl 0
loc 60
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
/** entries_scrolling.php v.1
4
 * XOOPS - PHP Content Management System
5
 * Copyright (c) 2017 <https://xoops.org>
6
 *
7
 * Module: lexikon 1.5 beta
8
 * Author : Yerres
9
 * Licence : GPL
10
 */
11
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
12
13
/**
14
 * @param $options
15
 * @return array
16
 */
17
function b_scrolling_term_show($options)
18
{
19
    global $xoopsDB, $xoopsUser;
20
    $myts = MyTextSanitizer:: getInstance();
21
22
    /** @var \XoopsModuleHandler $moduleHandler */
23
    $moduleHandler = xoops_getHandler('module');
24
    $lexikon       = $moduleHandler->getByDirname('lexikon');
25
    if (!isset($lxConfig)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $lxConfig seems to never exist and therefore isset should always be false.
Loading history...
26
        /** @var \XoopsConfigHandler $configHandler */
27
        $configHandler = xoops_getHandler('config');
28
        $lxConfig      = $configHandler->getConfigsByCat(0, $lexikon->getVar('mid'));
29
    }
30
    require_once XOOPS_ROOT_PATH . '/modules/lexikon/class/Utility.php';
31
32
    $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
33
    /** @var \XoopsGroupPermHandler $grouppermHandler */
34
    $grouppermHandler = xoops_getHandler('groupperm');
35
    $module_id        = $lexikon->getVar('mid');
36
    $allowed_cats     = $grouppermHandler->getItemIds('lexikon_view', $groups, $module_id);
37
38
    $block                = [];
39
    $block['speed']       = isset($options[1]) && '' != $options[1] ? $options[1] : '';
40
    $block['bgcolor']     = isset($options[2]) && '' != $options[2] ? $options[2] : '#FFFFFF';
41
    $block['direction']   = $options[3];
42
    $block['alternate']   = isset($options[4]) ? 1 : 0;
43
    $block['includedate'] = isset($options[6]) ? 1 : 0;
44
    $block['style']       = $options[7];
45
46
    if (!empty($options[10])) {
47
        $categories = array_filter(array_slice($options, 10));
48
    } else {
49
        $categories = $allowed_cats;
50
    }
51
    $categories = array_intersect($categories, $allowed_cats);
52
    $categories = implode(',', $categories);
53
    if (0 == count($categories)) {
0 ignored issues
show
Bug introduced by
$categories of type string is incompatible with the type Countable|array expected by parameter $value of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
    if (0 == count(/** @scrutinizer ignore-type */ $categories)) {
Loading history...
54
        return $block;
55
    }
56
57
    $sql    = $xoopsDB->query(
58
        '
59
      SELECT entryID, term, definition, datesub, html
60
      FROM ' . $xoopsDB->prefix('lxentries') . '
61
      WHERE datesub < ' . time() . " AND datesub > 0 AND offline = '0' AND submit = '0' AND request = '0' AND  categoryID IN (" . $categories . ')
62
      ORDER BY ' . $options[8] . ' ' . $options[9] . '
63
      LIMIT 0, ' . $options[0] . ' '
64
    );
65
    $totals = $xoopsDB->getRowsNum($sql);
66
67
    if ($totals > 1) {
68
        while (list($entryID, $term, $definition, $datesub, $html) = $xoopsDB->fetchRow($sql)) {
69
            $items         = [];
70
            $userlink      = '<a style="cursor:help;background-color: transparent;" href=\"' . XOOPS_URL . '/modules/' . $lexikon->dirname() . '/entry.php?entryID=' . (int)$entryID . '\">';
71
            $items['id']   = (int)$entryID;
72
            $items['term'] = htmlspecialchars($term, ENT_QUOTES | ENT_HTML5);
73
            if ($options[5] > 0) {
74
                $html                = 1 == $html ? 1 : 0;
75
                $definition          = preg_replace("/'/", '’', $definition);
76
                $items['definition'] = $utility::truncateTagSafe($myts->displayTarea($definition, $html), $options[5] + 3);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $utility seems to be never defined.
Loading history...
77
            } else {
78
                $items['definition'] = '';
79
            }
80
            if ('1' == $options[6]) {
81
                $items['date'] = formatTimestamp($datesub, $lxConfig['dateformat']);
82
            }
83
            $items['url']           = $userlink;
84
            $block['scrollitems'][] = $items;
85
        }
86
    }
87
88
    return $block;
89
}
90
91
/**
92
 * @param $options
93
 * @return string
94
 */
95
function b_scrolling_term_edit($options)
96
{
97
    global $xoopsDB;
98
    $myts = MyTextSanitizer:: getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
99
    $form = "<table style='width:100%' class='bg2'>";
100
    $form .= "<tr><th style='width:50%'>" . _OPTIONS . "</th><th style='width:50%'>" . _MB_LEXIKON_SETTINGS . '</th></tr>';
101
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_BLIMIT . "</td><td class='odd'><input type='text' name='options[0]' size='16' maxlength=3 value='" . $options[0] . "' ></td></tr>";
102
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_BSPEED . "</td><td class='odd'><input type='text' name='options[1]' size='16' maxlength=2 value='" . $options[1] . "' ></td></tr>";
103
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_BACKGROUNDCOLOR . "</td><td class='odd'><input type='text' name='options[2]' size='16'  value='" . $options[2] . "' ></td></tr>";
104
    //---
105
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_DIRECTION . "</td><td class='odd'><select name='options[3]'>";
106
    $form .= "<option value='up' " . (('up' === $options[3]) ? ' selected' : '') . '>' . _MB_LEXIKON_UP . "</option>\n";
107
    $form .= "<option value='down' " . (('down' === $options[3]) ? ' selected' : '') . '>' . _MB_LEXIKON_DOWN . "</option>\n";
108
    $form .= '</select></td></tr>';
109
    //---
110
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_ALTERNATE . "</td><td class='odd'>";
111
    $form .= "<input type='radio' name='options[4]' value='1'" . ((1 == $options[4]) ? ' checked' : '') . ' >' . _YES . '&nbsp;';
112
    $form .= "<input type='radio' name='options[4]' value='0'" . ((0 == $options[4]) ? ' checked' : '') . ' >' . _NO . '<br></td></tr>';
113
    //---
114
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_CHARS . " </td><td class='odd'><input type='text' name='options[5]' value='" . $options[5] . "' ></td></tr>";
115
    //---
116
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_TERMSTOSHOW . ' ' . _MB_LEXIKON_SHOWDATE . "</td><td class='odd'>";
117
    $form .= "<input type='radio' name='options[6]' value='1'" . ((1 == $options[6]) ? ' checked' : '') . ' >' . _YES . '&nbsp;';
118
    $form .= "<input type='radio' name='options[6]' value='0'" . ((0 == $options[6]) ? ' checked' : '') . ' >' . _NO . '<br></td></tr>';
119
    //---
120
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_DISP . "</td><td class='odd'><select name='options[7]'>";
121
    $form .= "<option value='0' " . (('0' == $options[7]) ? ' selected' : '') . '>' . _MB_LEXIKON_MARQUEE . "</option>\n";
122
    $form .= "<option value='1' " . (('1' == $options[7]) ? ' selected' : '') . '>' . _MB_LEXIKON_PAUSESCROLLER . "</option>\n";
123
    $form .= "<option value='2' " . (('2' == $options[7]) ? ' selected' : '') . '>' . _MB_LEXIKON_DOMTICKER . "</option>\n";
124
    $form .= '</select></td></tr>';
125
    //---
126
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_SORT . "</td><td class='odd'><select name='options[8]'>";
127
    $form .= "<option value='RAND()' " . (('RAND()' === $options[8]) ? ' selected' : '') . '>' . _MB_LEXIKON_RANDOM . "</option>\n";
128
    $form .= "<option value='datesub' " . (('datesub' === $options[8]) ? ' selected' : '') . '>' . _MB_LEXIKON_DATE . "</option>\n";
129
    $form .= "<option value='counter' " . (('counter' === $options[8]) ? ' selected' : '') . '>' . _MB_LEXIKON_HITS . "</option>\n";
130
    $form .= "<option value='term' " . (('term' === $options[8]) ? ' selected' : '') . '>' . _MB_LEXIKON_NAME . "</option>\n";
131
    $form .= '</select></td></tr>';
132
    //---
133
    $form .= "<tr><td class='even'>" . _MB_LEXIKON_ORDER . "</td><td class='odd'><select name='options[9]'>";
134
    $form .= "<option value='ASC' " . (('ASC' === $options[9]) ? ' selected' : '') . '>' . _ASCENDING . "</option>\n";
135
    $form .= "<option value='DESC' " . (('DESC' === $options[9]) ? ' selected' : '') . '>' . _DESCENDING . "</option>\n";
136
    $form .= '</select></td></tr>';
137
    //--- get allowed categories
138
    $isAll       = empty($options[10]) ? true : false;
139
    $options_cat = array_slice($options, 10);
140
    $form        .= "<tr><td class='even'>" . _MB_LEXIKON_CATEGORY . "</td><td class='odd'><select name=\"options[]\" multiple=\"multiple\">";
141
    $form        .= '<option value="0" ';
142
    if ($isAll) {
143
        $form .= ' selected="selected"';
144
    }
145
    $form      .= '>' . _ALL . '</option>';
146
    $resultcat = $xoopsDB->query('SELECT categoryID, name FROM ' . $xoopsDB->prefix('lxcategories') . ' ORDER BY categoryID ASC');
147
    while (list($categoryID, $name) = $xoopsDB->fetchRow($resultcat)) {
148
        $sel  = ($isAll || in_array($categoryID, $options_cat)) ? ' selected' : '';
149
        $form .= '<option value=' . $categoryID . " $sel>$categoryID : $name</option>\n";
150
    }
151
    $form .= '</select></td></tr>';
152
    $form .= '</table>';
153
    //--------
154
    return $form;
155
}
156