Conditions | 4 |
Paths | 8 |
Total Lines | 100 |
Code Lines | 41 |
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 |
||
72 | public function getForm(?bool $action = false): \XoopsThemeForm |
||
73 | { |
||
74 | if (false === $action) { |
||
75 | $action = $_SERVER['REQUEST_URI']; |
||
76 | } |
||
77 | |||
78 | /** @var Helper $helper */ |
||
79 | $helper = Helper::getInstance(); |
||
80 | $helper->loadLanguage('admin'); |
||
81 | |||
82 | $title = $this->isNew() ? \sprintf(\_AM_PEDIGREE_PEDIGREE_CONFIG_ADD) : \sprintf(\_AM_PEDIGREE_PEDIGREE_CONFIG_EDIT); |
||
83 | |||
84 | require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
||
85 | |||
86 | $form = new \XoopsThemeForm($title, 'form', $action, 'post', true); |
||
87 | $form->setExtra('enctype="multipart/form-data"'); |
||
88 | |||
89 | $form->addElement(new \XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDNAME, 'fieldname', 50, 255, $this->getVar('fieldname')), true); |
||
90 | $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_ISACTIVE, 'isactive', (int)$this->getVar('isactive')), false); |
||
91 | $fieldTypes = new \XoopsFormSelect(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDTYPE, 'fieldtype', $this->getVar('fieldtype'), false); |
||
92 | $fieldTypes->addOptionArray([ |
||
93 | 'DateSelect' => 'DateSelect', |
||
94 | 'Picture' => 'Picture', |
||
95 | 'radiobutton' => 'radiobutton', |
||
96 | 'selectbox' => 'selectbox', |
||
97 | 'textarea' => 'textarea', |
||
98 | 'textbox' => 'textbox', |
||
99 | 'urlfield' => 'urlfield', |
||
100 | ]); |
||
101 | $form->addElement($fieldTypes); |
||
102 | // $form->addElement(new \XoopsFormTextArea(_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDTYPE, "fieldtype", $this->getVar("fieldtype"), 4, 47), false); |
||
103 | $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_CONFIG_LOOKUPTABLE, 'lookupTable', 50, 255, $this->getVar('lookuptable')), false); |
||
104 | $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_CONFIG_DEFAULTVALUE, 'defaultValue', 50, 255, $this->getVar('defaultvalue')), false); |
||
105 | $form->addElement(new \XoopsFormText(\_AM_PEDIGREE_PEDIGREE_CONFIG_FIELDEXPLANATION, 'fieldExplanation', 50, 255, $this->getVar('fieldexplanation')), false); |
||
106 | $form->addElement(new \XoopsFormRadioYN(\_AM_PEDIGREE_PEDIGREE_CONFIG_HASSEARCH, 'hasSearch', (int)$this->getVar('hassearch')), false); |
||
107 | /* @todo: should be single select for either General Litter or Litter, can't have both */ |
||
108 | $currentType = $this->getVar('litter') ? 'litter' : 'generallitter'; |
||
109 | $litterRadio = new \XoopsFormRadio(_AM_PEDIGREE_PEDIGREE_CONFIG_LITTER_TYPE, 'littertype', $currentType); |
||
110 | $litterRadio->addOptionArray([ |
||
111 | 'litter' => _AM_PEDIGREE_PEDIGREE_CONFIG_LITTER, |
||
112 | 'generallitter' => _AM_PEDIGREE_PEDIGREE_CONFIG_GENERALLITTER, |
||
113 | ]); |
||
114 | $form->addElement($litterRadio, false); |
||
115 | // $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_LITTER, "litter", $this->getVar("litter")), false); |
||
116 | // $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_GENERALLITTER, "generallitter", $this->getVar("generallitter")), false); |
||
117 | $form->addElement(new \XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_SEARCHNAME, 'searchname', 50, 255, $this->getVar('searchname')), false); |
||
118 | $form->addElement(new \XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_SEARCHEXPLANATION, 'searchexplanation', 50, 255, $this->getVar('searchexplanation')), false); |
||
119 | $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINPEDIGREE, 'viewinpedigree', (int)$this->getVar('viewinpedigree')), false); |
||
120 | $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINADVANCED, 'viewinadvanced', (int)$this->getVar('viewinadvanced')), false); |
||
121 | $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINPIE, 'viewinpie', (int)$this->getVar('viewinpie')), false); |
||
122 | $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_VIEWINLIST, 'viewinlist', (int)$this->getVar('viewinlist')), false); |
||
123 | $form->addElement(new \XoopsFormRadioYN(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, 'locked', (int)$this->getVar('locked')), false); |
||
124 | $form->addElement(new \XoopsFormText(_AM_PEDIGREE_PEDIGREE_CONFIG_ORDER, 'order', 3, 8, (int)$this->getVar('order')), false); |
||
125 | // require_once XOOPS_ROOT_PATH."/class/tree.php"; |
||
126 | // $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsDB']->getVar("dirname")); |
||
127 | // $criteria = new \CriteriaCompo(); |
||
128 | // $criteria->setSort('_id'); |
||
129 | // $criteria->setOrder('ASC'); |
||
130 | // $_arr = $Handler->getAll(); |
||
131 | // $mytree = new \XoopsObjectTree($_arr, "_id", "_pid"); |
||
132 | // $form->addElement(new \XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, $mytree->makeSelBox("_pid", "_title","--", $this->getVar("_pid"),false))); |
||
133 | // |
||
134 | // require_once XOOPS_ROOT_PATH."/class/tree.php"; |
||
135 | // $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsModule']->getVar("dirname")); |
||
136 | // $criteria = new \CriteriaCompo(); |
||
137 | // $criteria->setSort('_id'); |
||
138 | // $criteria->setOrder('ASC'); |
||
139 | // $_arr = $Handler->getAll(); |
||
140 | // $mytree = new \XoopsObjectTree($_arr, "_id", "_pid"); |
||
141 | // $form->addElement(new \XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_ORDER, $mytree->makeSelBox("_pid", "_title","--", $this->getVar("_pid"),false))); |
||
142 | /* |
||
143 | require_once $GLOBALS['xoops']->path("class/tree.php"); |
||
144 | // $Handler = xoops_getModuleHandler("animal_", $GLOBALS['xoopsModule']->getVar("dirname")); |
||
145 | $Handler = Helper::getInstance()->getHandler('Fields'); |
||
146 | // $Handler = & $fieldsHandler; |
||
147 | $criteria = new \CriteriaCompo(); |
||
148 | $criteria->setSort('id'); |
||
149 | $criteria->setOrder('ASC'); |
||
150 | $_arr = $Handler->getAll(); |
||
151 | $mytree = new \XoopsObjectTree($_arr, "ID", "_pid"); |
||
152 | $form->addElement(new \XoopsFormLabel(_AM_PEDIGREE_PEDIGREE_CONFIG_LOCKED, $mytree->makeSelBox("_pid", "_title", "--", $this->getVar("_pid"), false))); |
||
153 | */ |
||
154 | $form->addElement(new \XoopsFormHidden('op', 'save_pedigree_fields')); |
||
155 | |||
156 | //Submit buttons |
||
157 | $form->addElement(new \XoopsFormButtonTray('fieldButtons', _SUBMIT, 'submit')); |
||
158 | |||
159 | /* |
||
160 | $buttonTray = new \XoopsFormElementTray("", ""); |
||
161 | $submit_button = new \XoopsFormButton("", "submit", _SUBMIT, "submit"); |
||
162 | $buttonTray->addElement($submit_button); |
||
163 | |||
164 | $cancel_button = new \XoopsFormButton("", "", _CANCEL, "cancel"); |
||
165 | $cancel_button->setExtra('onclick="history.go(-1)"'); |
||
166 | $buttonTray->addElement($cancel_button); |
||
167 | |||
168 | $form->addElement($buttonTray); |
||
169 | */ |
||
170 | |||
171 | return $form; |
||
172 | } |
||
283 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: