| Conditions | 13 |
| Paths | 1152 |
| Total Lines | 160 |
| Code Lines | 127 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 313 | public function completeCallback() |
||
| 314 | { |
||
| 315 | |||
| 316 | //can this field be searched |
||
| 317 | $search = $this->getValue('hassearch'); |
||
| 318 | if ('hassearch' === $search) { |
||
| 319 | $search = '1'; |
||
| 320 | $searchname = $this->getValue('searchname'); |
||
| 321 | $searchexplain = $this->getValue('searchexplain'); |
||
| 322 | } else { |
||
| 323 | $search = '0'; |
||
| 324 | $searchname = ''; |
||
| 325 | $searchexplain = ''; |
||
| 326 | } |
||
| 327 | //show in pedigree |
||
| 328 | $viewinpedigree = $this->getValue('viewinpedigree'); |
||
| 329 | if ('viewinpedigree' === $viewinpedigree) { |
||
| 330 | $viewinpedigree = '1'; |
||
| 331 | } else { |
||
| 332 | $viewinpedigree = '0'; |
||
| 333 | } |
||
| 334 | //show in advanced |
||
| 335 | $viewinadvanced = $this->getValue('viewinadvanced'); |
||
| 336 | if ('viewinadvanced' === $viewinadvanced) { |
||
| 337 | $viewinadvanced = '1'; |
||
| 338 | } else { |
||
| 339 | $viewinadvanced = '0'; |
||
| 340 | } |
||
| 341 | //show in pie |
||
| 342 | $viewinpie = $this->getValue('viewinpie'); |
||
| 343 | if ('viewinpie' === $viewinpie) { |
||
| 344 | $viewinpie = '1'; |
||
| 345 | } else { |
||
| 346 | $viewinpie = '0'; |
||
| 347 | } |
||
| 348 | //view in list |
||
| 349 | $viewinlist = $this->getValue('viewinlist'); |
||
| 350 | if ('viewinlist' === $viewinlist) { |
||
| 351 | $viewinlist = '1'; |
||
| 352 | } else { |
||
| 353 | $viewinlist = '0'; |
||
| 354 | } |
||
| 355 | //add a litter? |
||
| 356 | $litter = ('litter' === $this->getValue('litter')) ? '1' : '0'; |
||
| 357 | |||
| 358 | //general litter |
||
| 359 | $generallitter = ('generallitter' === $this->getValue('generalLitter')) ? '1' : '0'; |
||
| 360 | |||
| 361 | if (0 == !$this->getValue('field')) { |
||
| 362 | // field allready exists (editing mode) |
||
| 363 | |||
| 364 | //@todo refactor using class methods |
||
| 365 | $sql = 'UPDATE ' |
||
| 366 | . $GLOBALS['xoopsDB']->prefix('pedigree_fields') |
||
| 367 | . " SET fieldname = '" |
||
| 368 | . htmlspecialchars($this->getValue('name'), ENT_QUOTES | ENT_HTML5) |
||
| 369 | . "', fieldtype = '" |
||
| 370 | . $this->getValue('fieldtype') |
||
| 371 | . "', defaultvalue = '" |
||
| 372 | . $this->getValue('defaultvalue') |
||
| 373 | . "', fieldexplanation = '" |
||
| 374 | . $this->getValue('explain') |
||
| 375 | . "', hassearch = '" |
||
| 376 | . $search |
||
| 377 | . "', litter = '" |
||
| 378 | . $litter |
||
| 379 | . "', generallitter = '" |
||
| 380 | . $generallitter |
||
| 381 | . "', searchname = '" |
||
| 382 | . $searchname |
||
| 383 | . "', searchexplanation = '" |
||
| 384 | . $searchexplain |
||
| 385 | . "', viewinpedigree = '" |
||
| 386 | . $viewinpedigree |
||
| 387 | . "', viewinadvanced = '" |
||
| 388 | . $viewinadvanced |
||
| 389 | . "', viewinpie = '" |
||
| 390 | . $viewinpie |
||
| 391 | . "', viewinlist = '" |
||
| 392 | . $viewinlist |
||
| 393 | . "' WHERE id ='" |
||
| 394 | . $this->getValue('field') |
||
| 395 | . "'"; |
||
| 396 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 397 | //possible change defaultvalue for userfield |
||
| 398 | $sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('pedigree_tree') . ' CHANGE `user' . $this->getValue('field') . '` `user' . $this->getValue('field') . "` VARCHAR( 255 ) NOT NULL DEFAULT '" . $this->getValue('defaultvalue') . "'"; |
||
| 399 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 400 | $sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('pedigree_temp') . ' CHANGE `user' . $this->getValue('field') . '` `user' . $this->getValue('field') . "` VARCHAR( 1024 ) NOT NULL DEFAULT '" . $this->getValue('defaultvalue') . "'"; |
||
| 401 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 402 | $sql = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash') . ' CHANGE `user' . $this->getValue('field') . '` `user' . $this->getValue('field') . "` VARCHAR( 255 ) NOT NULL DEFAULT '" . $this->getValue('defaultvalue') . "'"; |
||
| 403 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 404 | } else { //this is a new field |
||
| 405 | $sql = 'SELECT MAX(id) AS lid FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' LIMIT 1'; |
||
| 406 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 407 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 408 | $nextfieldnum = $row['lid'] + 1; |
||
| 409 | } |
||
| 410 | //add userfield to various tables as a new field. |
||
| 411 | //always add at the end of the table |
||
| 412 | $tables = ['pedigree_tree', 'pedigree_temp', 'pedigree_trash']; |
||
| 413 | foreach ($tables as $table) { |
||
| 414 | $SQL = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($table) . ' ADD `user' . $nextfieldnum . "` VARCHAR( 255 ) NOT NULL DEFAULT '" . $this->getValue('defaultvalue') . "'"; |
||
| 415 | $GLOBALS['xoopsDB']->queryF($SQL); |
||
| 416 | } |
||
| 417 | //is a lookup table present |
||
| 418 | $lookup = $this->getValue('lookup1'); |
||
| 419 | if ('' == $lookup) { |
||
| 420 | $lookup = '0'; |
||
| 421 | } else { |
||
| 422 | $lookup = '1'; |
||
| 423 | //create table for lookupfield |
||
| 424 | $createtable = 'CREATE TABLE ' . $GLOBALS['xoopsDB']->prefix('pedigree_lookup' . $nextfieldnum) . ' (`id` INT( 10 ) NOT NULL ,`value` VARCHAR( 255 ) NOT NULL, `order` INT( 10 )) ENGINE = MyISAM'; |
||
| 425 | $GLOBALS['xoopsDB']->queryF($createtable); |
||
| 426 | //fill table |
||
| 427 | $count = $this->getValue('fc'); |
||
| 428 | for ($x = 1; $x < $count + 1; ++$x) { |
||
| 429 | $y = $x - 1; |
||
| 430 | $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_lookup' . $nextfieldnum) . " ( `id` , `value`, `order`) VALUES ('" . $y . "', '" . $this->getValue('lookup' . $x) . "','" . $y . "')"; |
||
| 431 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 432 | } |
||
| 433 | } |
||
| 434 | |||
| 435 | //Insert new record into pedigree_config |
||
| 436 | // $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . " VALUES ('" . $nextfieldnum . "', '1', '" . htmlspecialchars($this->getValue('name')) . "', '" . $this->getValue('fieldtype') . "', '" . $lookup . "', '" . $this->getValue('defaultvalue') . "', '" . $this->getValue('explain') . "', '" . $search . "', '" . $Litter . "', '" . $generalLitter . "', '" . $searchname . "', '" . $searchexplain . "', '" . $viewinpedigree . "', '" . $viewinadvanced . "', '" . $viewinpie . "', '" . $viewinlist . "','','" . $nextfieldnum . "')"; |
||
| 437 | $sql = 'INSERT INTO ' |
||
| 438 | . $GLOBALS['xoopsDB']->prefix('pedigree_fields') |
||
| 439 | . " VALUES ('" |
||
| 440 | . $nextfieldnum |
||
| 441 | . "', '1', '" |
||
| 442 | . $GLOBALS['xoopsDB']->escape(htmlspecialchars($this->getValue('name'), ENT_QUOTES | ENT_HTML5)) |
||
| 443 | . "', '" |
||
| 444 | . $GLOBALS['xoopsDB']->escape($this->getValue('fieldtype')) |
||
| 445 | . "', '" |
||
| 446 | . $GLOBALS['xoopsDB']->escape($lookup) |
||
| 447 | . "', '" |
||
| 448 | . $GLOBALS['xoopsDB']->escape($this->getValue('defaultvalue')) |
||
| 449 | . "', '" |
||
| 450 | . $GLOBALS['xoopsDB']->escape($this->getValue('explain')) |
||
| 451 | . "', '" |
||
| 452 | . $GLOBALS['xoopsDB']->escape($search) |
||
| 453 | . "', '" |
||
| 454 | . $GLOBALS['xoopsDB']->escape($Litter) |
||
| 455 | . "', '" |
||
| 456 | . $GLOBALS['xoopsDB']->escape($generallitter) |
||
| 457 | . "', '" |
||
| 458 | . $GLOBALS['xoopsDB']->escape($searchname) |
||
| 459 | . "', '" |
||
| 460 | . $GLOBALS['xoopsDB']->escape($searchexplain) |
||
| 461 | . "', '" |
||
| 462 | . $GLOBALS['xoopsDB']->escape($viewinpedigree) |
||
| 463 | . "', '" |
||
| 464 | . $GLOBALS['xoopsDB']->escape($viewinadvanced) |
||
| 465 | . "', '" |
||
| 466 | . $GLOBALS['xoopsDB']->escape($viewinpie) |
||
| 467 | . "', '" |
||
| 468 | . $GLOBALS['xoopsDB']->escape($viewinlist) |
||
| 469 | . "','','" |
||
| 470 | . $GLOBALS['xoopsDB']->escape($nextfieldnum) |
||
| 471 | . "')"; |
||
| 472 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 473 | } |
||
| 489 |