Conditions | 24 |
Paths | > 20000 |
Total Lines | 212 |
Code Lines | 131 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 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 |
||
37 | function virt() |
||
38 | { |
||
39 | global $xoopsTpl; |
||
40 | $moduleDirName = basename(__DIR__); |
||
41 | //get module configuration |
||
42 | /** @var XoopsModuleHandler $moduleHandler */ |
||
43 | $moduleHandler = xoops_getHandler('module'); |
||
44 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
45 | $configHandler = xoops_getHandler('config'); |
||
46 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
47 | $helper = Pedigree\Helper::getInstance(); |
||
48 | |||
49 | // if (isset($_GET['st'])) { |
||
50 | // $st = $_GET['st']; |
||
51 | // } else { |
||
52 | // $st = 0; |
||
53 | // } |
||
54 | // if (isset($_GET['l'])) { |
||
55 | // $l = $_GET['l']; |
||
56 | // } else { |
||
57 | // $l = 'A'; |
||
58 | // } |
||
59 | $st = Request::getInt('st', 0, 'GET'); |
||
60 | $l = Request::getString('l', 'A', 'GET'); |
||
61 | |||
62 | $xoopsTpl->assign('sire', '1'); |
||
63 | //create list of males dog to select from |
||
64 | $perPage = $helper->getConfig('perpage'); |
||
65 | //count total number of dogs |
||
66 | $numDog = 'SELECT COUNT(d.id) FROM ' |
||
67 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
68 | . ' d LEFT JOIN ' |
||
69 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
70 | . ' m ON m.id = d.mother LEFT JOIN ' |
||
71 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
72 | // . " f ON f.id = d.father WHERE d.roft = '0' and d.mother != '0' and d.father != '0' and m.mother != '0' and m.father != '0' and f.mother != '0' and f.father != '0' and d.naam LIKE '" . $l . "%'"; |
||
73 | . " f ON f.id = d.father WHERE d.roft = '0' AND d.mother != '0' AND d.father != '0' AND m.mother != '0' AND m.father != '0' AND f.mother != '0' AND f.father != '0' AND d.naam LIKE '" |
||
74 | . $GLOBALS['xoopsDB']->escape($l) |
||
75 | . "%'"; |
||
76 | $numRes = $GLOBALS['xoopsDB']->query($numDog); |
||
77 | //total number of dogs the query will find |
||
78 | list($numResults) = $GLOBALS['xoopsDB']->fetchRow($numRes); |
||
79 | //total number of pages |
||
80 | $numPages = floor($numResults / $perPage) + 1; |
||
81 | if (($numPages * $perPage) == ($numResults + $perPage)) { |
||
82 | --$numPages; |
||
83 | } |
||
84 | //find current page |
||
85 | $currentPage = floor($st / $perPage) + 1; |
||
86 | //create alphabet |
||
87 | $pages = ''; |
||
88 | for ($i = 65; $i <= 90; ++$i) { |
||
89 | if ($l == chr($i)) { |
||
90 | $pages .= '<b><a href="virtual.php?r=1&st=0&l=' . chr($i) . '">' . chr($i) . '</a></b> '; |
||
91 | } else { |
||
92 | $pages .= '<a href="virtual.php?r=1&st=0&l=' . chr($i) . '">' . chr($i) . '</a> '; |
||
93 | } |
||
94 | } |
||
95 | $pages .= '- '; |
||
96 | $pages .= '<a href="virtual.php?r=1&st=0&l=Ã…">Ã…</a> '; |
||
97 | $pages .= '<a href="virtual.php?r=1&st=0&l=Ö">Ö</a> '; |
||
98 | $pages .= '<br>'; |
||
99 | //create previous button |
||
100 | if (($numPages > 1) && ($currentPage > 1)) { |
||
101 | $pages .= '<a href="virtual.php?r=1&&l=' . $l . 'st=' . ($st - $perPage) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>  '; |
||
102 | } |
||
103 | //create numbers |
||
104 | $xLimit = $numPages + 1; |
||
105 | for ($x = 1; $x < $xLimit; ++$x) { |
||
106 | //create line break after 20 number |
||
107 | if (0 == ($x % 20)) { |
||
108 | $pages .= '<br>'; |
||
109 | } |
||
110 | if ($x != $currentPage) { |
||
111 | $pages .= '<a href="virtual.php?r=1&l=' . $l . '&st=' . ($perPage * ($x - 1)) . '">' . $x . '</a> '; |
||
112 | } else { |
||
113 | $pages .= $x . '  '; |
||
114 | } |
||
115 | } |
||
116 | //create next button |
||
117 | if ($numPages > 1) { |
||
118 | if ($currentPage < $numPages) { |
||
119 | $pages .= '<a href="virtual.php?r=1&l=' . $l . '&st=' . ($st + $perPage) . '">' . _MA_PEDIGREE_NEXT . '</a>  '; |
||
120 | } |
||
121 | } |
||
122 | |||
123 | //query |
||
124 | $queryString = 'SELECT d.*, d.id AS d_id, d.naam AS d_naam FROM ' |
||
125 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
126 | . ' d LEFT JOIN ' |
||
127 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
128 | . ' m ON m.id = d.mother LEFT JOIN ' |
||
129 | . $GLOBALS['xoopsDB']->prefix('pedigree_tree') |
||
130 | . " f ON f.id = d.father WHERE d.roft = '0' AND d.mother != '0' AND d.father != '0' AND m.mother != '0' AND m.father != '0' AND f.mother != '0' AND f.father != '0' AND d.naam LIKE '" |
||
131 | . $l |
||
132 | . "%' ORDER BY d.naam LIMIT " |
||
133 | . $st |
||
134 | . ', ' |
||
135 | . $perPage; |
||
136 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||
137 | |||
138 | $animal = new Pedigree\Animal(); |
||
139 | //test to find out how many user fields there are... |
||
140 | $fields = $animal->getNumOfFields(); |
||
141 | $numofcolumns = 1; |
||
142 | $columns[] = ['columnname' => 'Name']; |
||
143 | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
||
144 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
145 | $fieldType = $userField->getSetting('FieldType'); |
||
146 | $fieldObject = new $fieldType($userField, $animal); |
||
147 | //create empty string |
||
148 | $lookupValues = ''; |
||
149 | if ($userField->isActive() && $userField->inList()) { |
||
150 | if ($userField->hasLookup()) { |
||
151 | $lookupValues = $userField->lookupField($fields[$i]); |
||
152 | //debug information |
||
153 | //print_r($lookupValues); |
||
154 | } |
||
155 | $columns[] = [ |
||
156 | 'columnname' => $fieldObject->fieldname, |
||
157 | 'columnnumber' => $userField->getId(), |
||
158 | 'lookupval' => $lookupValues |
||
159 | ]; |
||
160 | ++$numofcolumns; |
||
161 | unset($lookupValues); |
||
162 | } |
||
163 | } |
||
164 | |||
165 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
166 | //create picture information |
||
167 | if ('' != $row['foto']) { |
||
168 | $camera = ' <img src="' . PEDIGREE_UPLOAD_URL . '/images/dog-icon25.png">'; |
||
169 | } else { |
||
170 | $camera = ''; |
||
171 | } |
||
172 | $name = stripslashes($row['d_naam']) . $camera; |
||
173 | //empty array |
||
174 | unset($columnvalue); |
||
175 | //fill array |
||
176 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||
177 | $x = $columns[$i]['columnnumber']; |
||
178 | //echo $x."columnnumber"; |
||
179 | if (is_array($columns[$i]['lookupval'])) { |
||
180 | foreach ($columns[$i]['lookupval'] as $key => $keyValue) { |
||
181 | if ($keyValue['id'] == $row['user' . $x]) { |
||
182 | //echo "key:".$row['user5']."<br>"; |
||
183 | $value = $keyValue['value']; |
||
184 | } |
||
185 | } |
||
186 | //debug information |
||
187 | ///echo $columns[$i]['columnname']."is an array !"; |
||
188 | } //format value - cant use object because of query count |
||
189 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
||
190 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||
191 | } else { |
||
192 | $value = $row['user' . $x]; |
||
193 | } |
||
194 | $columnvalue[] = ['value' => $value]; |
||
195 | unset($value); |
||
196 | } |
||
197 | $dogs[] = [ |
||
198 | 'id' => $row['d_id'], |
||
199 | 'name' => $name, |
||
200 | 'gender' => '<img src="assets/images/male.gif">', |
||
201 | 'link' => '<a href="virtual.php?f=dam&selsire=' . $row['d_id'] . '">' . $name . '</a>', |
||
202 | 'colour' => '', |
||
203 | 'number' => '', |
||
204 | 'usercolumns' => isset($columnvalue) ? $columnvalue : 0 |
||
205 | ]; |
||
206 | } |
||
207 | |||
208 | //add data to smarty template |
||
209 | //assign dog |
||
210 | if (isset($dogs)) { |
||
211 | $xoopsTpl->assign('dogs', $dogs); |
||
212 | } |
||
213 | $xoopsTpl->assign('columns', $columns); |
||
214 | $xoopsTpl->assign('numofcolumns', $numofcolumns); |
||
215 | $xoopsTpl->assign('tsarray', Pedigree\Utility::sortTable($numofcolumns)); |
||
216 | $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELSIRE, ['[father]' => $helper->getConfig('father')])); |
||
217 | $xoopsTpl->assign('pages', $pages); |
||
218 | |||
219 | $xoopsTpl->assign('virtualtitle', strtr(_MA_PEDIGREE_VIRUTALTIT, ['[mother]' => $helper->getConfig('mother')])); |
||
220 | $xoopsTpl->assign('virtualstory', strtr(_MA_PEDIGREE_VIRUTALSTO, [ |
||
221 | '[mother]' => $helper->getConfig('mother'), |
||
222 | '[father]' => $helper->getConfig('father'), |
||
223 | '[children]' => $helper->getConfig('children') |
||
224 | ])); |
||
225 | $xoopsTpl->assign('nextaction', '<b>' . strtr(_MA_PEDIGREE_VIRT_SIRE, ['[father]' => $helper->getConfig('father')]) . '</b>'); |
||
226 | // break; |
||
227 | |||
228 | //mb =========== FATHER LETTERS ============================= |
||
229 | $myObject = Pedigree\Helper::getInstance(); |
||
230 | $roft = 0; |
||
231 | // $criteria = $myObject->getHandler('Tree')->getActiveCriteria($roft); |
||
232 | $activeObject = 'Tree'; |
||
233 | $name = 'naam'; |
||
234 | $number1 = '1'; |
||
235 | $number2 = '0'; |
||
236 | // $link = "virtual.php?r={$number1}&st={$number2}&l="; |
||
237 | $link = "virtual.php?r={$number1}&st={$number2}&l="; |
||
238 | |||
239 | // http://localhost/257belgi/modules/pedigree/virtual.php?f=dam&selsire=35277 |
||
240 | |||
241 | $link2 = ''; |
||
242 | |||
243 | $criteria = $myObject->getHandler('Tree')->getActiveCriteria($roft); |
||
244 | // $criteria->setGroupby('UPPER(LEFT(' . $name . ',1))'); |
||
245 | |||
246 | $fatherArray['letters'] = Pedigree\Utility::lettersChoice($myObject, $activeObject, $criteria, $name, $link, $link2); |
||
247 | //$catarray['toolbar'] = pedigree_toolbar(); |
||
248 | $xoopsTpl->assign('fatherArray', $fatherArray); |
||
249 | |||
544 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths