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