| Conditions | 5 |
| Paths | 6 |
| Total Lines | 63 |
| Code Lines | 34 |
| 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 |
||
| 54 | public function __construct($target) |
||
| 55 | { |
||
| 56 | // global $helper; |
||
| 57 | $this->helper = $target->helper; |
||
| 58 | $this->targetObject = $target; |
||
| 59 | |||
| 60 | $title = $this->targetObject->isNew() ? \sprintf(AM_PEDIGREE_FIELDS_ADD) : \sprintf(AM_PEDIGREE_FIELDS_EDIT); |
||
| 61 | parent::__construct($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
||
| 62 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 63 | |||
| 64 | //include ID field, it's needed so the module knows if it is a new form or an edited form |
||
| 65 | |||
| 66 | $hidden = new \XoopsFormHidden('id', $this->targetObject->getVar('id')); |
||
| 67 | $this->addElement($hidden); |
||
| 68 | unset($hidden); |
||
| 69 | |||
| 70 | // Id |
||
| 71 | $this->addElement(new \XoopsFormLabel(AM_PEDIGREE_FIELDS_ID, $this->targetObject->getVar('id'), 'id')); |
||
| 72 | // Isactive |
||
| 73 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_ISACTIVE, 'isactive', 50, 255, $this->targetObject->getVar('isactive')), false); |
||
| 74 | // Fieldname |
||
| 75 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_FIELDNAME, 'fieldname', 50, 255, $this->targetObject->getVar('fieldname')), false); |
||
| 76 | // Fieldtype |
||
| 77 | $fieldtype = new \XoopsFormSelect(AM_PEDIGREE_FIELDS_FIELDTYPE, 'fieldtype', $this->targetObject->getVar('fieldtype')); |
||
| 78 | $optionsArray = Utility::enumerate('pedigree_fields', 'fieldtype'); |
||
| 79 | if (!\is_array($optionsArray)) { |
||
| 80 | throw new RuntimeException($optionsArray . ' must be an array.'); |
||
| 81 | } |
||
| 82 | foreach ($optionsArray as $enum) { |
||
| 83 | $fieldtype->addOption($enum, (\defined($enum) ? \constant($enum) : $enum)); |
||
| 84 | } |
||
| 85 | $this->addElement($fieldtype, false); |
||
| 86 | // Lookuptable |
||
| 87 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_LOOKUPTABLE, 'lookuptable', 50, 255, $this->targetObject->getVar('lookuptable')), false); |
||
| 88 | // Defaultvalue |
||
| 89 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_DEFAULTVALUE, 'defaultvalue', 50, 255, $this->targetObject->getVar('defaultvalue')), false); |
||
| 90 | // Fieldexplanation |
||
| 91 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_FIELDEXPLANATION, 'fieldexplanation', 50, 255, $this->targetObject->getVar('fieldexplanation')), false); |
||
| 92 | // Hassearch |
||
| 93 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_HASSEARCH, 'hassearch', 50, 255, $this->targetObject->getVar('hassearch')), false); |
||
| 94 | // Litter |
||
| 95 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_LITTER, 'litter', 50, 255, $this->targetObject->getVar('litter')), false); |
||
| 96 | // Generallitter |
||
| 97 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_GENERALLITTER, 'generallitter', 50, 255, $this->targetObject->getVar('generallitter')), false); |
||
| 98 | // Searchname |
||
| 99 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_SEARCHNAME, 'searchname', 50, 255, $this->targetObject->getVar('searchname')), false); |
||
| 100 | // Searchexplanation |
||
| 101 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_SEARCHEXPLANATION, 'searchexplanation', 50, 255, $this->targetObject->getVar('searchexplanation')), false); |
||
| 102 | // Viewinpedigree |
||
| 103 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_VIEWINPEDIGREE, 'viewinpedigree', 50, 255, $this->targetObject->getVar('viewinpedigree')), false); |
||
| 104 | // Viewinadvanced |
||
| 105 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_VIEWINADVANCED, 'viewinadvanced', 50, 255, $this->targetObject->getVar('viewinadvanced')), false); |
||
| 106 | // Viewinpie |
||
| 107 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_VIEWINPIE, 'viewinpie', 50, 255, $this->targetObject->getVar('viewinpie')), false); |
||
| 108 | // Viewinlist |
||
| 109 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_VIEWINLIST, 'viewinlist', 50, 255, $this->targetObject->getVar('viewinlist')), false); |
||
| 110 | // Locked |
||
| 111 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_LOCKED, 'locked', 50, 255, $this->targetObject->getVar('locked')), false); |
||
| 112 | // Order |
||
| 113 | $this->addElement(new \XoopsFormText(AM_PEDIGREE_FIELDS_ORDER, 'order', 50, 255, $this->targetObject->getVar('order')), false); |
||
| 114 | |||
| 115 | $this->addElement(new \XoopsFormHidden('op', 'save')); |
||
| 116 | $this->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
| 117 | } |
||
| 119 |