| Conditions | 13 |
| Paths | 1152 |
| Total Lines | 96 |
| Code Lines | 63 |
| 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 |
||
| 310 | public function completeCallback() |
||
| 311 | { |
||
| 312 | |||
| 313 | //can this field be searched |
||
| 314 | $search = $this->getValue('hassearch'); |
||
| 315 | if ($search === 'hassearch') { |
||
| 316 | $search = '1'; |
||
| 317 | $searchname = $this->getValue('searchname'); |
||
| 318 | $searchexplain = $this->getValue('searchexplain'); |
||
| 319 | } else { |
||
| 320 | $search = '0'; |
||
| 321 | $searchname = ''; |
||
| 322 | $searchexplain = ''; |
||
| 323 | } |
||
| 324 | //show in pedigree |
||
| 325 | $viewinpedigree = $this->getValue('viewinpedigree'); |
||
| 326 | if ($viewinpedigree === 'viewinpedigree') { |
||
| 327 | $viewinpedigree = '1'; |
||
| 328 | } else { |
||
| 329 | $viewinpedigree = '0'; |
||
| 330 | } |
||
| 331 | //show in advanced |
||
| 332 | $viewinadvanced = $this->getValue('viewinadvanced'); |
||
| 333 | if ($viewinadvanced === 'viewinadvanced') { |
||
| 334 | $viewinadvanced = '1'; |
||
| 335 | } else { |
||
| 336 | $viewinadvanced = '0'; |
||
| 337 | } |
||
| 338 | //show in pie |
||
| 339 | $viewinpie = $this->getValue('viewinpie'); |
||
| 340 | if ($viewinpie === 'viewinpie') { |
||
| 341 | $viewinpie = '1'; |
||
| 342 | } else { |
||
| 343 | $viewinpie = '0'; |
||
| 344 | } |
||
| 345 | //view in list |
||
| 346 | $viewinlist = $this->getValue('viewinlist'); |
||
| 347 | if ($viewinlist === 'viewinlist') { |
||
| 348 | $viewinlist = '1'; |
||
| 349 | } else { |
||
| 350 | $viewinlist = '0'; |
||
| 351 | } |
||
| 352 | //add a litter? |
||
| 353 | $litter = ('litter' === $this->getValue('litter')) ? '1' : '0'; |
||
| 354 | |||
| 355 | //general litter |
||
| 356 | $generallitter = ('generallitter' === $this->getValue('generalLitter')) ? '1' : '0'; |
||
| 357 | |||
| 358 | if (0 == !$this->getValue('field')) { |
||
| 359 | // field allready exists (editing mode) |
||
| 360 | |||
| 361 | //@todo refactor using class methods |
||
| 362 | $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . " SET fieldname = '" . htmlspecialchars($this->getValue('name')) . "', fieldtype = '" . $this->getValue('fieldtype') . "', defaultvalue = '" . $this->getValue('defaultvalue') . "', fieldexplanation = '" . $this->getValue('explain') . "', hassearch = '" . $search . "', litter = '" . $litter . "', generallitter = '" . $generallitter . "', searchname = '" . $searchname . "', searchexplanation = '" . $searchexplain . "', viewinpedigree = '" . $viewinpedigree . "', viewinadvanced = '" . $viewinadvanced . "', viewinpie = '" . $viewinpie . "', viewinlist = '" . $viewinlist . "' WHERE Id ='" . $this->getValue('field') . "'"; |
||
| 363 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 364 | //possible change defaultvalue for userfield |
||
| 365 | $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') . "'"; |
||
| 366 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 367 | $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') . "'"; |
||
| 368 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 369 | $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') . "'"; |
||
| 370 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 371 | } else { //this is a new field |
||
| 372 | $sql = 'SELECT MAX(Id) AS lid FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' LIMIT 1'; |
||
| 373 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
| 374 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||
| 375 | $nextfieldnum = $row['lid'] + 1; |
||
| 376 | } |
||
| 377 | //add userfield to various tables as a new field. |
||
| 378 | //always add at the end of the table |
||
| 379 | $tables = array('pedigree_tree', 'pedigree_temp', 'pedigree_trash'); |
||
| 380 | foreach ($tables as $table) { |
||
| 381 | $SQL = 'ALTER TABLE ' . $GLOBALS['xoopsDB']->prefix($table) . ' ADD `user' . $nextfieldnum . "` VARCHAR( 255 ) NOT NULL DEFAULT '" . $this->getValue('defaultvalue') . "'"; |
||
| 382 | $GLOBALS['xoopsDB']->queryF($SQL); |
||
| 383 | } |
||
| 384 | //is a lookup table present |
||
| 385 | $lookup = $this->getValue('lookup1'); |
||
| 386 | if ('' == $lookup) { |
||
| 387 | $lookup = '0'; |
||
| 388 | } else { |
||
| 389 | $lookup = '1'; |
||
| 390 | //create table for lookupfield |
||
| 391 | $createtable = 'CREATE TABLE ' . $GLOBALS['xoopsDB']->prefix('pedigree_lookup' . $nextfieldnum) . ' (`Id` INT( 10 ) NOT NULL ,`value` VARCHAR( 255 ) NOT NULL, `order` INT( 10 )) ENGINE = MyISAM'; |
||
| 392 | $GLOBALS['xoopsDB']->queryF($createtable); |
||
| 393 | //fill table |
||
| 394 | $count = $this->getValue('fc'); |
||
| 395 | for ($x = 1; $x < $count + 1; ++$x) { |
||
| 396 | $y = $x - 1; |
||
| 397 | $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_lookup' . $nextfieldnum) . " ( `Id` , `value`, `order`) VALUES ('" . $y . "', '" . $this->getValue('lookup' . $x) . "','" . $y . "')"; |
||
| 398 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 399 | } |
||
| 400 | } |
||
| 401 | |||
| 402 | //Insert new record into pedigree_config |
||
| 403 | // $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 . "')"; |
||
| 404 | $sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . " VALUES ('" . $nextfieldnum . "', '1', '" . $GLOBALS['xoopsDB']->escape(htmlspecialchars($this->getValue('name'))) . "', '" . $GLOBALS['xoopsDB']->escape($this->getValue('fieldtype')) . "', '" . $GLOBALS['xoopsDB']->escape($lookup) . "', '" . $GLOBALS['xoopsDB']->escape($this->getValue('defaultvalue')) . "', '" . $GLOBALS['xoopsDB']->escape($this->getValue('explain')) . "', '" . $GLOBALS['xoopsDB']->escape($search) . "', '" . $GLOBALS['xoopsDB']->escape($Litter) . "', '" . $GLOBALS['xoopsDB']->escape($generalLitter) . "', '" . $GLOBALS['xoopsDB']->escape($searchname) . "', '" . $GLOBALS['xoopsDB']->escape($searchexplain) . "', '" . $GLOBALS['xoopsDB']->escape($viewinpedigree) . "', '" . $GLOBALS['xoopsDB']->escape($viewinadvanced) . "', '" . $GLOBALS['xoopsDB']->escape($viewinpie) . "', '" . $GLOBALS['xoopsDB']->escape($viewinlist) . "','','" . $GLOBALS['xoopsDB']->escape($nextfieldnum) . "')"; |
||
| 405 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 406 | } |
||
| 422 |