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

menu_block.php ➔ menu_block()   F

Complexity

Conditions 39
Paths > 20000

Size

Total Lines 192
Code Lines 137

Duplication

Lines 24
Ratio 12.5 %

Importance

Changes 0
Metric Value
cc 39
eloc 137
nc 13056000
nop 0
dl 24
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
use XoopsModules\Pedigree;
8
9
// Include any constants used for internationalizing templates.
10
$moduleDirName = basename(dirname(__DIR__));
11
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

11
/** @scrutinizer ignore-call */ 
12
xoops_loadLanguage('main', $moduleDirName);
Loading history...
12
//xoops_loadLanguage('main', $moduleDirName);
13
// Include any common code for this module.
14
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
 * @todo: move hard coded language strings to language file
19
 *
20
 * @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...
21
 */
22
function menu_block()
23
{
24
    global $xoopsTpl, $xoopsUser, $pedigree;
25
    $moduleDirName = basename(dirname(__DIR__));
26
    /*
27
    //get module configuration
28
    $moduleHandler = xoops_getHandler('module');
29
    $module        = $moduleHandler->getByDirname($moduleDirName);
30
    $configHandler = xoops_getHandler('config');
31
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
32
*/
33
    //colour variables
34
    $colors  = explode(',', $helper->getConfig('colourscheme'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $helper seems to be never defined.
Loading history...
35
    $actlink = $colors[0];
0 ignored issues
show
Unused Code introduced by
The assignment to $actlink is dead and can be removed.
Loading history...
36
    $even    = $colors[1];
0 ignored issues
show
Unused Code introduced by
The assignment to $even is dead and can be removed.
Loading history...
37
    $odd     = $colors[2];
0 ignored issues
show
Unused Code introduced by
The assignment to $odd is dead and can be removed.
Loading history...
38
    $text    = $colors[3];
0 ignored issues
show
Unused Code introduced by
The assignment to $text is dead and can be removed.
Loading history...
39
    $hovlink = $colors[4];
0 ignored issues
show
Unused Code introduced by
The assignment to $hovlink is dead and can be removed.
Loading history...
40
    $head    = $colors[5];
0 ignored issues
show
Unused Code introduced by
The assignment to $head is dead and can be removed.
Loading history...
41
    $body    = $colors[6];
0 ignored issues
show
Unused Code introduced by
The assignment to $body is dead and can be removed.
Loading history...
42
    $title   = $colors[7];
0 ignored issues
show
Unused Code introduced by
The assignment to $title is dead and can be removed.
Loading history...
43
44
    /*
45
        //inline-css
46
        echo '<style>';
47
        //text-colour
48
        echo 'body {margin: 0;padding: 0;background: ' . $body . ';color: ' . $text . ";font-size: 62.5%; font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; text-align: left;}";
49
        //link-colour
50
        echo 'a, h2 a:hover, h3 a:hover { color: ' . $actlink . '; text-decoration: none; }';
51
        //link hover colour
52
        echo 'a:hover { color: ' . $hovlink . '; text-decoration: underline; }';
53
        //th
54
        echo 'th {padding: 2px;color: #ffffff;background: ' . $title . ';font-family: Verdana, Arial, Helvetica, sans-serif;vertical-align: middle;}';
55
        echo 'td#centercolumn th { color: #fff; background: ' . $title . '; vertical-align: middle; }';
56
        //head
57
        echo '.head {background-color: ' . $head . '; padding: 3px; font-weight: normal;}';
58
        //even
59
        echo '.even {background-color: ' . $even . '; padding: 3px;}';
60
        echo 'tr.even td {background-color: ' . $even . '; padding: 3px;}';
61
        //odd
62
        echo '.odd {background-color: ' . $odd . '; padding: 3px;}';
63
        echo 'tr.odd td {background-color: ' . $odd . '; padding: 3px;}';
64
        echo '</style>';
65
    */
66
67
    //iscurrent user a module admin ?
68
    $xoopsModule = XoopsModule::getByDirname($moduleDirName);
69
    if (!empty($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...
70
        && $xoopsUser->isAdmin($xoopsModule->mid())) {
71
        $modadmin = true;
72
    } else {
73
        $modadmin = false;
74
    }
75
    $counter   = 1;
76
    $menuwidth = 4;
77
78
    $x       = $_SERVER['PHP_SELF'];
79
    $lastpos = my_strrpos($x, '/');
80
    $len     = strlen($x);
81
    $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

81
    $curpage = substr($x, /** @scrutinizer ignore-type */ $lastpos, $len);
Loading history...
82
    if (1 == $helper->getConfig('showwelcome')) {
83
        if ('/welcome.php' === $curpage) {
84
            $title = '<b>Welcome</b>';
85
        } else {
86
            $title = 'Welcome';
87
        }
88
        $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...
89
        ++$counter;
90
        if ($counter == $menuwidth) {
91
            $counter = 1;
92
        }
93
    }
94
    if ('/index.php' === $curpage || '/result.php' === $curpage) {
95
        $title = '<b>View/Search ' . $helper->getConfig('animalTypes') . '</b>';
96
    } else {
97
        $title = 'View/Search ' . $helper->getConfig('animalTypes');
98
    }
99
    $menuarray[] = ['title' => $title, 'link' => 'index.php', 'counter' => $counter];
100
    ++$counter;
101
    if ($counter == $menuwidth) {
102
        $counter = 1;
103
    }
104
    if ('/add_dog.php' === $curpage) {
105
        $title = '<b>Add a ' . $helper->getConfig('animalType') . '</b>';
106
    } else {
107
        $title = 'Add a ' . $helper->getConfig('animalType');
108
    }
109
    $menuarray[] = ['title' => $title, 'link' => 'add_dog.php', 'counter' => $counter];
110
    ++$counter;
111
    if ($counter == $menuwidth) {
112
        $counter = 1;
113
    }
114
    if ('1' == $helper->getConfig('uselitter')) {
115
        if ('/add_litter.php' === $curpage) {
116
            $title = '<b>Add a ' . $helper->getConfig('litter') . '</b>';
117
        } else {
118
            $title = 'Add a ' . $helper->getConfig('litter');
119
        }
120
        $menuarray[] = ['title' => $title, 'link' => 'add_litter.php', 'counter' => $counter];
121
        ++$counter;
122
        if ($counter == $menuwidth) {
123
            $counter = 1;
124
        }
125
    }
126
    if ('1' == $helper->getConfig('ownerbreeder')) {
127
        if ('/breeder.php' === $curpage || '/owner.php' === $curpage) {
128
            $title = '<b>View owners/breeders</b>';
129
        } else {
130
            $title = 'View owners/breeders';
131
        }
132
        $menuarray[] = ['title' => $title, 'link' => 'breeder.php', 'counter' => $counter];
133
        ++$counter;
134
        if ($counter == $menuwidth) {
135
            $counter = 1;
136
        }
137
        if ('/add_breeder.php' === $curpage) {
138
            $title = '<b>Add an owner/breeder</b>';
139
        } else {
140
            $title = 'Add an owner/breeder';
141
        }
142
        $menuarray[] = ['title' => $title, 'link' => 'add_breeder.php', 'counter' => $counter];
143
        ++$counter;
144
        if ($counter == $menuwidth) {
145
            $counter = 1;
146
        }
147
    }
148
    if ('/advanced.php' === $curpage) {
149
        $title = '<b>Advanced info</b>';
150
    } else {
151
        $title = 'Advanced info';
152
    }
153
    $menuarray[] = ['title' => $title, 'link' => 'advanced.php', 'counter' => $counter];
154
    ++$counter;
155
    if ($counter == $menuwidth) {
156
        $counter = 1;
157
    }
158
    if ('1' == $helper->getConfig('proversion')) {
159
        if ('/virtual.php' === $curpage) {
160
            $title = '<b>Virtual mating</b>';
161
        } else {
162
            $title = 'Virtual Mating';
163
        }
164
        $menuarray[] = ['title' => $title, 'link' => 'virtual.php', 'counter' => $counter];
165
        ++$counter;
166
        if ($counter == $menuwidth) {
167
            $counter = 1;
168
        }
169
    }
170
    if ('/latest.php' === $curpage) {
171
        $title = '<b>latest additions</b>';
172
    } else {
173
        $title = 'latest additions';
174
    }
175
    $menuarray[] = ['title' => $title, 'link' => 'latest.php', 'counter' => $counter];
176
    ++$counter;
177
    if ($counter == $menuwidth) {
178
        $counter = 1;
179
    }
180
    if (true === $modadmin) {
181
        if ('/tools.php' === $curpage) {
182
            $title = '<b>Webmaster tools</b>';
183
        } else {
184
            $title = 'Webmaster tools';
185
        }
186
        $menuarray[] = ['title' => $title, 'link' => 'tools.php?op=index', 'counter' => $counter];
187
        ++$counter;
188
        if ($counter == $menuwidth) {
189
            $counter = 1;
190
        }
191
        $title       = 'Logout';
192
        $menuarray[] = ['title' => $title, 'link' => '../../user.php?op=logout', 'counter' => $counter];
193
        ++$counter;
194
        if ($counter == $menuwidth) {
195
            $counter = 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $counter is dead and can be removed.
Loading history...
196
        }
197
    } else {
198
        if ('/user.php' === $curpage) {
199
            $title = '<b>User login</b>';
200
        } else {
201
            $title = 'User login';
202
        }
203
        $menuarray[] = ['title' => $title, 'link' => '../../user.php', 'counter' => $counter];
204
        ++$counter;
205
        if ($counter == $menuwidth) {
206
            $counter = 1;
207
        }
208
    }
209
210
    //create path taken
211
    //showpath();
212
    $xoopsTpl->assign('menuarray', $menuarray);
213
214
    //return the template contents
215
    return $xoopsTpl;
216
}
217
218
/**
219
 * @param     $haystack
220
 * @param     $needle
221
 * @param int $offset
222
 *
223
 * @return bool|int
224
 */
225
function my_strrpos($haystack, $needle, $offset = 0)
226
{
227
    // same as strrpos, except $needle can be a string
228
    $strrpos = false;
229
    if (is_string($haystack) && is_string($needle) && is_numeric($offset)) {
230
        $strlen = strlen($haystack);
231
        $strpos = strpos(strrev(substr($haystack, $offset)), strrev($needle));
232
        if (is_numeric($strpos)) {
0 ignored issues
show
introduced by
The condition is_numeric($strpos) is always true.
Loading history...
233
            $strrpos = $strlen - $strpos - strlen($needle);
234
        }
235
    }
236
237
    return $strrpos;
238
}
239