Passed
Branch master (48d769)
by Michael
02:30
created

menu_block()   F

Complexity

Conditions 39
Paths > 20000

Size

Total Lines 192
Code Lines 137

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 39
eloc 137
nc 13056000
nop 0
dl 0
loc 192
rs 2
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
//    pedigree
4
//        Copyright 2004, James Cotton
5
//         http://www.dobermannvereniging.nl
6
7
// Include any constants used for internationalizing templates.
8
9
use XoopsModules\Pedigree;
10
11
$moduleDirName = basename(__DIR__);
12
xoops_loadLanguage('main', $moduleDirName);
0 ignored issues
show
Bug introduced by
The function xoops_loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

12
/** @scrutinizer ignore-call */ 
13
xoops_loadLanguage('main', $moduleDirName);
Loading history...
13
14
// Include any common code for this module.
15
require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/common.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
16
17
/**
18
 * @return XoopsTpl
0 ignored issues
show
Bug introduced by
The type XoopsTpl was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
 */
20
function menu_block()
21
{
22
    //    global $apppath;
23
24
    //get module configuration
25
    /** @var XoopsModuleHandler $moduleHandler */
26
    $moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

26
    $moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
27
    $module        = $moduleHandler->getByDirname($moduleDirName);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirName does not exist. Did you maybe mean $module?
Loading history...
28
    $configHandler = xoops_getHandler('config');
29
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
30
31
    //colour variables
32
    $colors  = explode(';', $moduleConfig['colourscheme']);
33
    $actlink = $colors[0];
34
    $even    = $colors[1];
35
    $odd     = $colors[2];
36
    $text    = $colors[3];
37
    $hovlink = $colors[4];
38
    $head    = $colors[5];
39
    $body    = $colors[6];
40
    $title   = $colors[7];
41
    //inline-css
42
    echo '<style>';
43
    //text-colour
44
    echo 'body {margin: 0;padding: 0;background: ' . $body . ';color: ' . $text . ";font-size: 100%; /* <-- Resets 1em to 10px */font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; text-align: left;}";
45
    //link-colour
46
    echo 'a, h2 a:hover, h3 a:hover { color: ' . $actlink . '; text-decoration: none; }';
47
    //link hover colour
48
    echo 'a:hover { color: ' . $hovlink . '; text-decoration: underline; }';
49
    //th
50
    echo 'th {padding: 2px;color: #ffffff;background: ' . $title . ';font-family: Verdana, Arial, Helvetica, sans-serif;vertical-align: middle;}';
51
    echo 'td#centercolumn th { color: #fff; background: ' . $title . '; vertical-align: middle; }';
52
    //head
53
    echo '.head {background-color: ' . $head . '; padding: 3px; font-weight: normal;}';
54
    //even
55
    echo '.even {background-color: ' . $even . '; padding: 3px;}';
56
    echo 'tr.even td {background-color: ' . $even . '; padding: 3px;}';
57
    //odd
58
    echo '.odd {background-color: ' . $odd . '; padding: 3px;}';
59
    echo 'tr.odd td {background-color: ' . $odd . '; padding: 3px;}';
60
    echo '</style>';
61
62
    //is current user a module admin ?
63
    if (!empty($GLOBALS['xoopsUser']) && ($GLOBALS['xoopsUser'] instanceof \XoopsUser)
0 ignored issues
show
Bug introduced by
The type XoopsUser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
64
        && $GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) {
65
        $isAdmin = true;
66
    } else {
67
        $isAdmin = false;
68
    }
69
70
    $counter   = 1;
71
    $menuwidth = 4;
72
73
    $x       = $_SERVER['PHP_SELF'];
74
    $lastpos = my_strrpos($x, '/');
75
    $len     = strlen($x);
76
    $curpage = substr($x, $lastpos, $len);
0 ignored issues
show
Bug introduced by
It seems like $lastpos can also be of type false; however, parameter $start of substr() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

76
    $curpage = substr($x, /** @scrutinizer ignore-type */ $lastpos, $len);
Loading history...
77
    if ('1' == $moduleConfig['showwelcome']) {
78
        if ('/welcome.php' === $curpage) {
79
            $title = '<b>' . _MA_PEDIGREE_WELCOME . '</b>';
80
        } else {
81
            $title = _MA_PEDIGREE_WELCOME;
82
        }
83
        $menuarray[] = ['title' => $title, 'link' => 'welcome.php', 'counter' => $counter];
0 ignored issues
show
Comprehensibility Best Practice introduced by
$menuarray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $menuarray = array(); before regardless.
Loading history...
84
        ++$counter;
85
        if ($counter == $menuwidth) {
86
            $counter = 1;
87
        }
88
    }
89
    if ('/index.php' === $curpage || '/result.php' == $curpage) {
90
        $title = '<b>' . _MA_PEDIGREE_VIEWSEARCH . $moduleConfig['animalTypes'] . '</b>';
91
    } else {
92
        $title = '_MA_PEDIGREE_VIEWSEARCH ' . $moduleConfig['animalTypes'];
93
    }
94
    $menuarray[] = ['title' => $title, 'link' => 'result.php', 'counter' => $counter];
95
    ++$counter;
96
    if ($counter == $menuwidth) {
97
        $counter = 1;
98
    }
99
    if ('/index.php' === $curpage) {
100
        $title = '<b>' . _MA_PEDIGREE_ADD_A . $moduleConfig['animalType'] . '</b>';
101
    } else {
102
        $title = 'PED_ADD_A ' . $moduleConfig['animalType'];
103
    }
104
    $menuarray[] = ['title' => $title, 'link' => 'add_dog.php', 'counter' => $counter];
105
    ++$counter;
106
    if ($counter == $menuwidth) {
107
        $counter = 1;
108
    }
109
    if ('1' == $moduleConfig['uselitter']) {
110
        if ('/index.php' === $curpage) {
111
            $title = '<b>' . _MA_PEDIGREE_ADD_LITTER . $moduleConfig['litter'] . '</b>';
112
        } else {
113
            $title = '_MA_PEDIGREE_ADD_LITTER ' . $moduleConfig['litter'];
114
        }
115
        $menuarray[] = ['title' => $title, 'link' => 'add_litter.php', 'counter' => $counter];
116
        ++$counter;
117
        if ($counter == $menuwidth) {
118
            $counter = 1;
119
        }
120
    }
121
    if ('1' == $moduleConfig['ownerbreeder']) {
122
        if ('/index.php' === $curpage || '/owner.php' === $curpage) {
123
            $title = '<b>' . _MA_PEDIGREE_VIEW_OWNBREED . '</b>';
124
        } else {
125
            $title = '_MA_PEDIGREE_VIEW_OWNBREED';
126
        }
127
        $menuarray[] = ['title' => $title, 'link' => 'breeder.php', 'counter' => $counter];
128
        ++$counter;
129
        if ($counter == $menuwidth) {
130
            $counter = 1;
131
        }
132
        if ('/index.php' === $curpage || '/add_breeder.php' === $curpage) {
133
            $title = '<b>' . _MA_PEDIGREE_ADD_OWNBREED . '</b>';
134
        } else {
135
            $title = '_MA_PEDIGREE_ADD_OWNBREED';
136
        }
137
        $menuarray[] = ['title' => $title, 'link' => 'add_breeder.php', 'counter' => $counter];
138
        ++$counter;
139
        if ($counter == $menuwidth) {
140
            $counter = 1;
141
        }
142
    }
143
    if ('/index.php' === $curpage || '/advanced.php' === $curpage) {
144
        $title = '<b>' . _MA_PEDIGREE_ADVANCE_INFO . '</b>';
145
    } else {
146
        $title = '_MA_PEDIGREE_ADVANCE_INFO';
147
    }
148
    $menuarray[] = ['title' => $title, 'link' => 'advanced.php', 'counter' => $counter];
149
    ++$counter;
150
    if ($counter == $menuwidth) {
151
        $counter = 1;
152
    }
153
    if ('1' == $moduleConfig['proversion']) {
154
        if ('/index.php' === $curpage || '/virtual.php' === $curpage) {
155
            $title = '<b>' . _MA_PEDIGREE_VIRUTALTIT . '</b>';
156
        } else {
157
            $title = '_MA_PEDIGREE_VIRUTALTIT';
158
        }
159
        $menuarray[] = ['title' => $title, 'link' => 'virtual.php', 'counter' => $counter];
160
        ++$counter;
161
        if ($counter == $menuwidth) {
162
            $counter = 1;
163
        }
164
    }
165
    if ('/index.php' === $curpage || '/latest.php' === $curpage) {
166
        $title = '<b>' . _MA_PEDIGREE_LATEST_ADD . '</b>';
167
    } else {
168
        $title = '_MA_PEDIGREE_LATEST_ADD';
169
    }
170
    $menuarray[] = ['title' => $title, 'link' => 'latest.php', 'counter' => $counter];
171
    ++$counter;
172
    if ($counter == $menuwidth) {
173
        $counter = 1;
174
    }
175
    if ($isAdmin) {
176
        if ('/index.php' === $curpage || '/tools.php' === $curpage) {
177
            $title = '<b>' . _MA_PEDIGREE_WEB_TOOLS . '</b>';
178
        } else {
179
            $title = '_MA_PEDIGREE_WEB_TOOLS';
180
        }
181
        $menuarray[] = ['title' => $title, 'link' => 'tools.php?op=index', 'counter' => $counter];
182
        ++$counter;
183
        if ($counter == $menuwidth) {
184
            $counter = 1;
185
        }
186
187
        $title       = _MA_PEDIGREE_USER_LOGOUT;
188
        $menuarray[] = ['title' => $title, 'link' => '../../user.php?op=logout', 'counter' => $counter];
189
        ++$counter;
190
        if ($counter == $menuwidth) {
191
            $counter = 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $counter is dead and can be removed.
Loading history...
192
        }
193
    } else {
194
        if ('/user.php' === $curpage) {
195
            $title = '._MA_PEDIGREE_USER_LOGIN.';
196
        } else {
197
            $title = _MA_PEDIGREE_USER_LOGIN;
198
        }
199
        $menuarray[] = ['title' => $title, 'link' => '../../user.php', 'counter' => $counter];
200
        ++$counter;
201
        if ($counter == $menuwidth) {
202
            $counter = 1;
203
        }
204
    }
205
206
    //create path taken
207
    //showpath();
208
    $GLOBALS['xoopsTpl']->assign('menuarray', $menuarray);
209
210
    //return the template contents
211
    return $GLOBALS['xoopsTpl'];
212
}
213
214
/**
215
 * @param     $haystack
216
 * @param     $needle
217
 * @param int $offset
218
 *
219
 * @return bool|int
220
 */
221
function my_strrpos($haystack, $needle, $offset = 0)
222
{
223
    // same as strrpos, except $needle can be a string
224
    $strrpos = false;
225
    if (is_string($haystack) && is_string($needle) && is_numeric($offset)) {
226
        $strlen = strlen($haystack);
227
        $strpos = strpos(strrev(substr($haystack, $offset)), strrev($needle));
228
        if (is_numeric($strpos)) {
0 ignored issues
show
introduced by
The condition is_numeric($strpos) is always true.
Loading history...
229
            $strrpos = $strlen - $strpos - strlen($needle);
230
        }
231
    }
232
233
    return $strrpos;
234
}
235