Conditions | 39 |
Paths | > 20000 |
Total Lines | 192 |
Code Lines | 137 |
Lines | 24 |
Ratio | 12.5 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
22 | function menu_block() |
||
23 | { |
||
24 | global $xoopsTpl, $xoopsUser; |
||
25 | $moduleDirName = basename(dirname(__DIR__)); |
||
26 | //get module configuration |
||
27 | $moduleHandler = xoops_getHandler('module'); |
||
28 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
29 | $configHandler = xoops_getHandler('config'); |
||
30 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
31 | |||
32 | //colour variables |
||
33 | $colors = explode(',', $moduleConfig['colourscheme']); |
||
34 | $actlink = $colors[0]; |
||
35 | $even = $colors[1]; |
||
36 | $odd = $colors[2]; |
||
37 | $text = $colors[3]; |
||
38 | $hovlink = $colors[4]; |
||
39 | $head = $colors[5]; |
||
40 | $body = $colors[6]; |
||
41 | $title = $colors[7]; |
||
42 | |||
43 | /* |
||
44 | //inline-css |
||
45 | echo '<style>'; |
||
46 | //text-colour |
||
47 | 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;}"; |
||
48 | //link-colour |
||
49 | echo 'a, h2 a:hover, h3 a:hover { color: ' . $actlink . '; text-decoration: none; }'; |
||
50 | //link hover colour |
||
51 | echo 'a:hover { color: ' . $hovlink . '; text-decoration: underline; }'; |
||
52 | //th |
||
53 | echo 'th {padding: 2px;color: #ffffff;background: ' . $title . ';font-family: Verdana, Arial, Helvetica, sans-serif;vertical-align: middle;}'; |
||
54 | echo 'td#centercolumn th { color: #fff; background: ' . $title . '; vertical-align: middle; }'; |
||
55 | //head |
||
56 | echo '.head {background-color: ' . $head . '; padding: 3px; font-weight: normal;}'; |
||
57 | //even |
||
58 | echo '.even {background-color: ' . $even . '; padding: 3px;}'; |
||
59 | echo 'tr.even td {background-color: ' . $even . '; padding: 3px;}'; |
||
60 | //odd |
||
61 | echo '.odd {background-color: ' . $odd . '; padding: 3px;}'; |
||
62 | echo 'tr.odd td {background-color: ' . $odd . '; padding: 3px;}'; |
||
63 | echo '</style>'; |
||
64 | */ |
||
65 | |||
66 | //iscurrent user a module admin ? |
||
67 | $xoopsModule = XoopsModule::getByDirname('pedigree'); |
||
68 | if ((!empty($xoopsUser)) && ($GLOBALS['xoopsUser'] instanceof XoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) { |
||
69 | $modadmin = true; |
||
70 | } else { |
||
71 | $modadmin = false; |
||
72 | } |
||
73 | $counter = 1; |
||
74 | $menuwidth = 4; |
||
75 | |||
76 | $x = $_SERVER['PHP_SELF']; |
||
77 | $lastpos = my_strrpos($x, '/'); |
||
78 | $len = strlen($x); |
||
79 | $curpage = substr($x, $lastpos, $len); |
||
80 | if (1 == $moduleConfig['showwelcome']) { |
||
81 | if ('/welcome.php' === $curpage) { |
||
82 | $title = '<b>Welcome</b>'; |
||
83 | } else { |
||
84 | $title = 'Welcome'; |
||
85 | } |
||
86 | $menuarray[] = array('title' => $title, 'link' => 'welcome.php', 'counter' => $counter); |
||
87 | ++$counter; |
||
88 | if ($counter == $menuwidth) { |
||
89 | $counter = 1; |
||
90 | } |
||
91 | } |
||
92 | if ($curpage === '/index.php' || $curpage === '/result.php') { |
||
93 | $title = '<b>View/Search ' . $moduleConfig['animalTypes'] . '</b>'; |
||
94 | } else { |
||
95 | $title = 'View/Search ' . $moduleConfig['animalTypes']; |
||
96 | } |
||
97 | $menuarray[] = array('title' => $title, 'link' => 'index.php', 'counter' => $counter); |
||
98 | ++$counter; |
||
99 | if ($counter == $menuwidth) { |
||
100 | $counter = 1; |
||
101 | } |
||
102 | if ($curpage === '/add_dog.php') { |
||
103 | $title = '<b>Add a ' . $moduleConfig['animalType'] . '</b>'; |
||
104 | } else { |
||
105 | $title = 'Add a ' . $moduleConfig['animalType']; |
||
106 | } |
||
107 | $menuarray[] = array('title' => $title, 'link' => 'add_dog.php', 'counter' => $counter); |
||
108 | ++$counter; |
||
109 | if ($counter == $menuwidth) { |
||
110 | $counter = 1; |
||
111 | } |
||
112 | View Code Duplication | if ($moduleConfig['uselitter'] == '1') { |
|
113 | if ($curpage === '/add_litter.php') { |
||
114 | $title = '<b>Add a ' . $moduleConfig['litter'] . '</b>'; |
||
115 | } else { |
||
116 | $title = 'Add a ' . $moduleConfig['litter']; |
||
117 | } |
||
118 | $menuarray[] = array('title' => $title, 'link' => 'add_litter.php', 'counter' => $counter); |
||
119 | ++$counter; |
||
120 | if ($counter == $menuwidth) { |
||
121 | $counter = 1; |
||
122 | } |
||
123 | } |
||
124 | if ($moduleConfig['ownerbreeder'] == '1') { |
||
125 | if ($curpage === '/breeder.php' || $curpage === '/owner.php') { |
||
126 | $title = '<b>View owners/breeders</b>'; |
||
127 | } else { |
||
128 | $title = 'View owners/breeders'; |
||
129 | } |
||
130 | $menuarray[] = array('title' => $title, 'link' => 'breeder.php', 'counter' => $counter); |
||
131 | ++$counter; |
||
132 | if ($counter == $menuwidth) { |
||
133 | $counter = 1; |
||
134 | } |
||
135 | if ($curpage === '/add_breeder.php') { |
||
136 | $title = '<b>Add an owner/breeder</b>'; |
||
137 | } else { |
||
138 | $title = 'Add an owner/breeder'; |
||
139 | } |
||
140 | $menuarray[] = array('title' => $title, 'link' => 'add_breeder.php', 'counter' => $counter); |
||
141 | ++$counter; |
||
142 | if ($counter == $menuwidth) { |
||
143 | $counter = 1; |
||
144 | } |
||
145 | } |
||
146 | if ($curpage === '/advanced.php') { |
||
147 | $title = '<b>Advanced info</b>'; |
||
148 | } else { |
||
149 | $title = 'Advanced info'; |
||
150 | } |
||
151 | $menuarray[] = array('title' => $title, 'link' => 'advanced.php', 'counter' => $counter); |
||
152 | ++$counter; |
||
153 | if ($counter == $menuwidth) { |
||
154 | $counter = 1; |
||
155 | } |
||
156 | if ($moduleConfig['proversion'] == '1') { |
||
157 | if ($curpage === '/virtual.php') { |
||
158 | $title = '<b>Virtual mating</b>'; |
||
159 | } else { |
||
160 | $title = 'Virtual Mating'; |
||
161 | } |
||
162 | $menuarray[] = array('title' => $title, 'link' => 'virtual.php', 'counter' => $counter); |
||
163 | ++$counter; |
||
164 | if ($counter == $menuwidth) { |
||
165 | $counter = 1; |
||
166 | } |
||
167 | } |
||
168 | if ($curpage === '/latest.php') { |
||
169 | $title = '<b>latest additions</b>'; |
||
170 | } else { |
||
171 | $title = 'latest additions'; |
||
172 | } |
||
173 | $menuarray[] = array('title' => $title, 'link' => 'latest.php', 'counter' => $counter); |
||
174 | ++$counter; |
||
175 | if ($counter == $menuwidth) { |
||
176 | $counter = 1; |
||
177 | } |
||
178 | if ($modadmin === true) { |
||
179 | if ($curpage === '/tools.php') { |
||
180 | $title = '<b>Webmaster tools</b>'; |
||
181 | } else { |
||
182 | $title = 'Webmaster tools'; |
||
183 | } |
||
184 | $menuarray[] = array('title' => $title, 'link' => 'tools.php?op=index', 'counter' => $counter); |
||
185 | ++$counter; |
||
186 | if ($counter == $menuwidth) { |
||
187 | $counter = 1; |
||
188 | } |
||
189 | $title = 'Logout'; |
||
190 | $menuarray[] = array('title' => $title, 'link' => '../../user.php?op=logout', 'counter' => $counter); |
||
191 | ++$counter; |
||
192 | if ($counter == $menuwidth) { |
||
193 | $counter = 1; |
||
194 | } |
||
195 | View Code Duplication | } else { |
|
196 | if ($curpage === '/user.php') { |
||
197 | $title = '<b>User login</b>'; |
||
198 | } else { |
||
199 | $title = 'User login'; |
||
200 | } |
||
201 | $menuarray[] = array('title' => $title, 'link' => '../../user.php', 'counter' => $counter); |
||
202 | ++$counter; |
||
203 | if ($counter == $menuwidth) { |
||
204 | $counter = 1; |
||
205 | } |
||
206 | } |
||
207 | |||
208 | //create path taken |
||
209 | //showpath(); |
||
210 | $xoopsTpl->assign('menuarray', $menuarray); |
||
211 | //return the template contents |
||
212 | return $xoopsTpl; |
||
213 | } |
||
214 | |||
236 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.