Conditions | 37 |
Paths | > 20000 |
Total Lines | 266 |
Code Lines | 162 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
130 | function sire() |
||
131 | { |
||
132 | global $xoopsTpl, $xoopsUser, $xoopsDB; |
||
133 | $moduleDirName = basename(__DIR__); |
||
134 | //debug option ! |
||
135 | //print_r($_POST); die(); |
||
136 | //get module configuration |
||
137 | /** @var XoopsModuleHandler $moduleHandler */ |
||
138 | $moduleHandler = xoops_getHandler('module'); |
||
139 | $module = $moduleHandler->getByDirname($moduleDirName); |
||
140 | $configHandler = xoops_getHandler('config'); |
||
141 | $moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
||
142 | |||
143 | //check for access |
||
144 | $xoopsModule = XoopsModule::getByDirname($moduleDirName); |
||
145 | if (empty($GLOBALS['xoopsUser']) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)) { |
||
146 | redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST); |
||
147 | } |
||
148 | // $userid = $_POST['userid']; |
||
149 | // if (empty($random)) { |
||
150 | // $random = $_POST['random']; |
||
151 | // } |
||
152 | // if (isset($_GET['random'])) { |
||
153 | // $random = $_GET['random']; |
||
154 | // } |
||
155 | // if (empty($st)) { |
||
156 | // $st = 0; |
||
157 | // } |
||
158 | // if (isset($_GET['st'])) { |
||
159 | // $st = $_GET['st']; |
||
160 | // } |
||
161 | $userid = Request::getInt('userid', 0, 'post'); |
||
162 | $random = Request::getInt('random', 0); |
||
163 | $st = Request::getInt('st', 0); |
||
164 | $userfields = ''; |
||
165 | $name = ''; |
||
166 | $roft = ''; |
||
167 | for ($count = 1; $count < 11; ++$count) { |
||
168 | $namelitter = 'name' . $count; |
||
169 | $roftlitter = 'roft' . $count; |
||
170 | //check for an empty name |
||
171 | if ('' !== $_POST[$namelitter]) { |
||
172 | $name .= ':' . Request::getString('namelitter', '', 'POST'); |
||
173 | $roft .= ':' . Request::getString('roftlitter', '', 'POST'); |
||
174 | } else { |
||
175 | if (1 == $count) { |
||
176 | redirect_header('add_litter.php', 3, _MA_PEDIGREE_ADD_NAMEPLZ); |
||
177 | } |
||
178 | } |
||
179 | } |
||
180 | |||
181 | $id_breeder = Request::getInt('id_breeder', 0, 'POST'); |
||
182 | |||
183 | //make the redirect |
||
184 | if (!isset($_GET['r'])) { |
||
185 | //create animal object |
||
186 | $animal = new Pedigree\Animal(); |
||
187 | //test to find out how many user fields there are.. |
||
188 | $fields = $animal->getNumOfFields(); |
||
189 | sort($fields); |
||
190 | $usersql = ''; |
||
191 | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
||
192 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
193 | $fieldType = $userField->getSetting('FieldType'); |
||
194 | $fieldObject = new $fieldType($userField, $animal); |
||
195 | $defvalue = $fieldObject->defaultvalue; |
||
196 | //emtpy string to house the different values for this userfield |
||
197 | $withinfield = ''; |
||
198 | for ($count = 1; $count < 11; ++$count) { |
||
199 | if ('' !== $_POST['name' . $count]) { |
||
200 | if (isset($_POST[$count . 'user' . $fields[$i]])) { |
||
201 | //debug option |
||
202 | //echo $count.'user'.$fields[$i]."=".$_POST[$count.'user'.$fields[$i]]."<br>"; |
||
203 | $withinfield .= ':' . $_POST[$count . 'user' . $fields[$i]]; |
||
204 | } else { |
||
205 | if ($userField->isActive() && $userField->generalLitter() && !$userField->isLocked()) { |
||
206 | //use $_POST value if this is a general litter field |
||
207 | $withinfield .= ':' . $_POST['-user' . $fields[$i]]; |
||
208 | } else { |
||
209 | //create $withinfield for fields not added to the litter |
||
210 | $withinfield .= ':' . $defvalue; |
||
211 | } |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | //debug option |
||
216 | //echo "user".$fields[$i]." - ".$withinfield."<br>"; |
||
217 | $user{$fields[$i]} = $withinfield; |
||
218 | } |
||
219 | //insert into pedigree_temp |
||
220 | // $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . " VALUES ('" . $random . "','" . Pedigree\Utility::unHtmlEntities($name) . "','0','" . $id_breeder . "','" . $userid . "','" . $roft . "','','','', ''"; |
||
221 | $query = 'INSERT INTO ' |
||
222 | . $GLOBALS['xoopsDB']->prefix('pedigree_temp') |
||
223 | . " VALUES ('" |
||
224 | . Request::getInt($random) |
||
225 | . "','" |
||
226 | . Request::getInt(Pedigree\Utility::unHtmlEntities($name)) |
||
227 | . "','0','" |
||
228 | . Request::getInt($id_breeder) |
||
229 | . "','" |
||
230 | . Request::getInt($userid) |
||
231 | . "','" |
||
232 | . Request::getInt($roft) |
||
233 | . "','','','', ''"; |
||
234 | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
||
235 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
236 | $fieldType = $userField->getSetting('FieldType'); |
||
237 | $fieldObject = new $fieldType($userField, $animal); |
||
238 | //do we only need to create a query for active fields ? |
||
239 | $query .= ",'" . $user{$fields[$i]} . "'"; |
||
240 | } |
||
241 | $query .= ')'; |
||
242 | //debug options |
||
243 | //echo $query."<br>"; die(); |
||
244 | $GLOBALS['xoopsDB']->query($query); |
||
245 | redirect_header('add_litter.php?f=sire&random=' . $random . '&st=' . $st . '&r=1&l=a', 1, strtr(_MA_PEDIGREE_ADD_SIREPLZ, ['[father]' => $moduleConfig['father']])); |
||
246 | } |
||
247 | //find letter on which to start else set to 'a' |
||
248 | $l = Request::getWord('l', 'a', 'GET'); |
||
249 | |||
250 | //assign 'sire' to the template |
||
251 | $xoopsTpl->assign('sire', '1'); |
||
252 | //create list of males dog to select from |
||
253 | $perPage = $moduleConfig['perpage']; |
||
254 | //count total number of dogs |
||
255 | $numDog = 'SELECT id FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft='0' AND naam LIKE '" . $l . "%'"; |
||
256 | $numRes = $GLOBALS['xoopsDB']->query($numDog); |
||
257 | //total number of dogs the query will find |
||
258 | $numResults = $GLOBALS['xoopsDB']->getRowsNum($numRes); |
||
259 | //total number of pages |
||
260 | $numPages = floor($numResults / $perPage) + 1; |
||
261 | if (($numPages * $perPage) == ($numResults + $perPage)) { |
||
262 | --$numPages; |
||
263 | } |
||
264 | //find current page |
||
265 | $currentPage = floor($st / $perPage) + 1; |
||
266 | //create alphabet |
||
267 | $pages = ''; |
||
268 | for ($i = 65; $i <= 90; ++$i) { |
||
269 | if ($l == chr($i)) { |
||
270 | $pages .= '<b><a href="add_litter.php?f=sire&r=1&r=1&random=' . $random . '&l=' . chr($i) . '">' . chr($i) . '</a></b> '; |
||
271 | } else { |
||
272 | $pages .= '<a href="add_litter.php?f=sire&r=1&r=1&random=' . $random . '&l=' . chr($i) . '">' . chr($i) . '</a> '; |
||
273 | } |
||
274 | } |
||
275 | $pages .= '- '; |
||
276 | $pages .= '<a href="add_litter.php?f=sire&r=1&random=' . $random . '&l=Ã…">Ã…</a> '; |
||
277 | $pages .= '<a href="add_litter.php?f=sire&r=1&random=' . $random . '&l=Ö">Ö</a> '; |
||
278 | //create linebreak |
||
279 | $pages .= '<br>'; |
||
280 | //create previous button |
||
281 | if ($numPages > 1) { |
||
282 | if ($currentPage > 1) { |
||
283 | $pages .= '<a href="add_litter.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st - $perPage) . '">' . _MA_PEDIGREE_PREVIOUS . '</a>  '; |
||
284 | } |
||
285 | } |
||
286 | //create numbers |
||
287 | for ($x = 1; $x < ($numPages + 1); ++$x) { |
||
288 | //create line break after 20 number |
||
289 | if (0 == ($x % 20)) { |
||
290 | $pages .= '<br>'; |
||
291 | } |
||
292 | if ($x != $currentPage) { |
||
293 | $pages .= '<a href="add_litter.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($perPage * ($x - 1)) . '">' . $x . '</a> '; |
||
294 | } else { |
||
295 | $pages .= $x . '  '; |
||
296 | } |
||
297 | } |
||
298 | //create next button |
||
299 | if ($numPages > 1) { |
||
300 | if ($currentPage < $numPages) { |
||
301 | $pages .= '<a href="add_litter.php?f=sire&r=1&l=' . $l . '&random=' . $random . '&st=' . ($st + $perPage) . '">' . _MA_PEDIGREE_NEXT . '</a>  '; |
||
302 | } |
||
303 | } |
||
304 | //query |
||
305 | $queryString = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . " WHERE roft = '0' AND naam LIKE '" . $l . "%' ORDER BY naam LIMIT " . $st . ', ' . $perPage; |
||
306 | $result = $GLOBALS['xoopsDB']->query($queryString); |
||
307 | |||
308 | $animal = new Pedigree\Animal(); |
||
309 | //test to find out how many user fields there are... |
||
310 | $fields = $animal->getNumOfFields(); |
||
311 | $numofcolumns = 1; |
||
312 | $columns[] = ['columnname' => 'Name']; |
||
313 | for ($i = 0, $iMax = count($fields); $i < $iMax; ++$i) { |
||
314 | $userField = new Pedigree\Field($fields[$i], $animal->getConfig()); |
||
315 | $fieldType = $userField->getSetting('FieldType'); |
||
316 | $fieldObject = new $fieldType($userField, $animal); |
||
317 | //create empty string |
||
318 | $lookupValues = ''; |
||
319 | if ($userField->isActive() && $userField->inList()) { |
||
320 | if ($userField->hasLookup()) { |
||
321 | $lookupValues = $userField->lookupField($fields[$i]); |
||
322 | //debug information |
||
323 | //print_r($lookupValues); |
||
324 | } |
||
325 | $columns[] = [ |
||
326 | 'columnname' => $fieldObject->fieldname, |
||
327 | 'columnnumber' => $userField->getId(), |
||
328 | 'lookupval' => $lookupValues |
||
329 | ]; |
||
330 | ++$numofcolumns; |
||
331 | unset($lookupValues); |
||
332 | } |
||
333 | } |
||
334 | |||
335 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||
336 | $empty[] = ['value' => '']; |
||
337 | } |
||
338 | $dogs [] = [ |
||
339 | 'id' => '0', |
||
340 | 'name' => '', |
||
341 | 'gender' => '', |
||
342 | 'link' => '<a href="add_litter.php?f=dam&random=' . $random . '&selsire=0">' . strtr(_MA_PEDIGREE_ADD_SIREUNKNOWN, ['[father]' => $moduleConfig['father']]) . '</a>', |
||
343 | 'colour' => '', |
||
344 | 'number' => '', |
||
345 | 'usercolumns' => $empty |
||
346 | ]; |
||
347 | |||
348 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
349 | //create picture information |
||
350 | if ('' != $row['foto']) { |
||
351 | $camera = ' <img src="assets/images/camera.png">'; |
||
352 | } else { |
||
353 | $camera = ''; |
||
354 | } |
||
355 | $name = stripslashes($row['naam']) . $camera; |
||
356 | //empty array |
||
357 | unset($columnvalue); |
||
358 | //fill array |
||
359 | for ($i = 1; $i < $numofcolumns; ++$i) { |
||
360 | $x = $columns[$i]['columnnumber']; |
||
361 | if (is_array($columns[$i]['lookupval'])) { |
||
362 | foreach ($columns[$i]['lookupval'] as $key => $keyValue) { |
||
363 | if ($key == $row['user' . $x]) { |
||
364 | $value = $keyValue['value']; |
||
365 | } |
||
366 | } |
||
367 | //debug information |
||
368 | ///echo $columns[$i]['columnname']."is an array !"; |
||
369 | } //format value - cant use object because of query count |
||
370 | elseif (0 === strncmp($row['user' . $x], 'http://', 7)) { |
||
371 | $value = '<a href="' . $row['user' . $x] . '">' . $row['user' . $x] . '</a>'; |
||
372 | } else { |
||
373 | $value = $row['user' . $x]; |
||
374 | } |
||
375 | $columnvalue[] = ['value' => $value]; |
||
376 | } |
||
377 | $dogs[] = [ |
||
378 | 'id' => $row['id'], |
||
379 | 'name' => $name, |
||
380 | 'gender' => '<img src="assets/images/male.gif">', |
||
381 | 'link' => '<a href="add_litter.php?f=dam&random=' . $random . '&selsire=' . $row['id'] . '">' . $name . '</a>', |
||
382 | 'colour' => '', |
||
383 | 'number' => '', |
||
384 | 'usercolumns' => $columnvalue |
||
385 | ]; |
||
386 | } |
||
387 | |||
388 | //add data to smarty template |
||
389 | //assign dog |
||
390 | $xoopsTpl->assign('dogs', $dogs); |
||
391 | $xoopsTpl->assign('columns', $columns); |
||
392 | $xoopsTpl->assign('numofcolumns', $numofcolumns); |
||
393 | $xoopsTpl->assign('tsarray', Pedigree\Utility::sortTable($numofcolumns)); |
||
394 | $xoopsTpl->assign('nummatch', strtr(_MA_PEDIGREE_ADD_SELSIRE, ['[father]' => $moduleConfig['father']])); |
||
395 | $xoopsTpl->assign('pages', $pages); |
||
396 | } |
||
654 |
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