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