Conditions | 15 |
Paths | 672 |
Total Lines | 108 |
Code Lines | 86 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
101 | private function getTemplatesUserPagesItemPanel($moduleDirname, $tableId, $tableMid, $tableName, $tableSoleName, $tableRate, $tableBroken, $language) |
||
102 | { |
||
103 | $fields = $this->getTableFields($tableMid, $tableId); |
||
104 | $ret = ''; |
||
105 | $retNumb = ''; |
||
106 | $fieldId = ''; |
||
107 | $ccFieldId = ''; |
||
108 | $keyDouble = ''; |
||
109 | foreach (\array_keys($fields) as $f) { |
||
110 | if (0 == $f) { |
||
111 | $fieldId = $fields[$f]->getVar('field_name'); |
||
112 | $ccFieldId = $this->getCamelCase($fieldId, false, true); |
||
113 | $keyDouble = $this->sc->getSmartyDoubleVar($tableSoleName, $fieldId); |
||
114 | } |
||
115 | $fieldElement = $fields[$f]->getVar('field_element'); |
||
116 | if (1 == $fields[$f]->getVar('field_user')) { |
||
117 | if (1 == $fields[$f]->getVar('field_thead')) { |
||
118 | switch ($fieldElement) { |
||
119 | default: |
||
120 | //case 2: |
||
121 | $fieldName = $fields[$f]->getVar('field_name'); |
||
122 | $rpFieldName = $this->getRightString($fieldName); |
||
123 | $doubleVar = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
124 | $retNumb .= $this->hc->getHtmlHNumb($doubleVar, '3', 'panel-title', "\t"); |
||
125 | break; |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | $ret .= $this->hc->getHtmlI('', '', $ccFieldId . '_' . $keyDouble); |
||
131 | $ret .= $this->hc->getHtmlDiv($retNumb, 'panel-heading'); |
||
132 | $retElem = ''; |
||
133 | foreach (\array_keys($fields) as $f) { |
||
134 | $fieldElement = $fields[$f]->getVar('field_element'); |
||
135 | if (1 == $fields[$f]->getVar('field_user')) { |
||
136 | if (1 == $fields[$f]->getVar('field_tbody')) { |
||
137 | switch ($fieldElement) { |
||
138 | default: |
||
139 | //case 3: |
||
140 | //case 4: |
||
141 | $fieldName = $fields[$f]->getVar('field_name'); |
||
142 | $rpFieldName = $this->getRightString($fieldName); |
||
143 | $doubleVar = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
144 | $retElem .= $this->hc->getHtmlSpan($doubleVar, 'col-sm-9 justify', "\t"); |
||
145 | break; |
||
146 | case Constants::FIELD_ELE_IMAGELIST: |
||
147 | $fieldName = $fields[$f]->getVar('field_name'); |
||
148 | $rpFieldName = $this->getRightString($fieldName); |
||
149 | $singleVar = $this->sc->getSmartySingleVar('xoops_icons32_url'); |
||
150 | $doubleVar = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
151 | $img = $this->hc->getHtmlImage($singleVar . '/' . $doubleVar, (string)$tableName); |
||
152 | $retElem .= $this->hc->getHtmlSpan($img, 'col-sm-3', "\t"); |
||
153 | unset($img); |
||
154 | break; |
||
155 | case Constants::FIELD_ELE_UPLOADIMAGE: |
||
156 | $fieldName = $fields[$f]->getVar('field_name'); |
||
157 | $rpFieldName = $this->getRightString($fieldName); |
||
158 | $singleVar = $this->sc->getSmartySingleVar($moduleDirname . '_upload_url'); |
||
159 | $doubleVar = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
160 | $img = $this->hc->getHtmlImage($singleVar . "/images/{$tableName}/" . $doubleVar, (string)$tableName); |
||
161 | $retElem .= $this->hc->getHtmlSpan($img, 'col-sm-3',"\t"); |
||
162 | unset($img); |
||
163 | break; |
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | } |
||
168 | $ret .= $this->hc->getHtmlDiv($retElem, 'panel-body'); |
||
169 | |||
170 | $retFoot = ''; |
||
171 | foreach (\array_keys($fields) as $f) { |
||
172 | if (1 == $fields[$f]->getVar('field_user')) { |
||
173 | if (1 == $fields[$f]->getVar('field_tfoot')) { |
||
174 | $fieldName = $fields[$f]->getVar('field_name'); |
||
175 | $rpFieldName = $this->getRightString($fieldName); |
||
176 | $langConst = \mb_strtoupper($tableSoleName) . '_' . \mb_strtoupper($rpFieldName); |
||
177 | $lang = $this->sc->getSmartyConst($language, $langConst); |
||
178 | $doubleVar = $this->sc->getSmartyDoubleVar($tableSoleName, $rpFieldName); |
||
179 | $retFoot .= $this->hc->getHtmlSpan($lang . ': ' . $doubleVar, 'block-pie justify',"\t"); |
||
180 | } |
||
181 | } |
||
182 | } |
||
183 | |||
184 | $anchors = ''; |
||
185 | $lang = $this->sc->getSmartyConst($language, \mb_strtoupper($tableName) . '_LIST'); |
||
186 | $contIf = $this->hc->getHtmlAnchor($tableName . '.php?op=list&start=<{$start}>&limit=<{$limit}>#' .$ccFieldId . '_' . $keyDouble, $lang, $lang, '', 'btn btn-success right', '', "\t\t\t", "\n"); |
||
187 | $lang = $this->sc->getSmartyConst($language, 'DETAILS'); |
||
188 | $contElse = $this->hc->getHtmlAnchor($tableName . ".php?op=show&{$fieldId}=" . $keyDouble . '&start=<{$start}>&limit=<{$limit}>', $lang, $lang, '', 'btn btn-success right', '', "\t\t\t", "\n"); |
||
189 | $anchors .= $this->sc->getSmartyConditions('showItem', '', '', $contIf, $contElse, '', '', "\t\t"); |
||
190 | $lang = $this->sc->getSmartyConst('', '_EDIT'); |
||
191 | $contIf = $this->hc->getHtmlAnchor($tableName . ".php?op=edit&{$fieldId}=" . $keyDouble . '&start=<{$start}>&limit=<{$limit}>', $lang, $lang, '', 'btn btn-primary right', '', "\t\t\t", "\n"); |
||
192 | $lang = $this->sc->getSmartyConst('', '_CLONE'); |
||
193 | $contIf .= $this->hc->getHtmlAnchor($tableName . ".php?op=clone&{$fieldId}_source=" . $keyDouble, $lang, $lang, '', 'btn btn-primary right', '', "\t\t\t", "\n"); |
||
194 | $lang = $this->sc->getSmartyConst('', '_DELETE'); |
||
195 | $contIf .= $this->hc->getHtmlAnchor($tableName . ".php?op=delete&{$fieldId}=" . $keyDouble, $lang, $lang, '', 'btn btn-danger right', '', "\t\t\t", "\n"); |
||
196 | $anchors .= $this->sc->getSmartyConditions('permEdit', '', '', $contIf, false, '', '', "\t\t"); |
||
197 | if (1 == $tableBroken) { |
||
198 | $lang = $this->sc->getSmartyConst($language, 'BROKEN'); |
||
199 | $anchors .= $this->hc->getHtmlAnchor($tableName . ".php?op=broken&{$fieldId}=" . $keyDouble . '&start=<{$start}>&limit=<{$limit}>', $lang, $lang, '', 'btn btn-warning right', '', "\t\t", "\n"); |
||
200 | } |
||
201 | $retFoot .= $this->hc->getHtmlDiv($anchors, 'col-sm-12 right',"\t", "\n"); |
||
202 | $ret .= $this->hc->getHtmlDiv($retFoot, 'panel-foot'); |
||
203 | if ($tableRate) { |
||
204 | $rate = $this->sc->getSmartyIncludeFile($moduleDirname, 'rate', false, false, "\t", "\n", 'item=$' . $tableSoleName); |
||
205 | $ret .= $this->sc->getSmartyConditions('rating', '', '', $rate, false); |
||
206 | } |
||
207 | |||
208 | return $ret; |
||
209 | } |
||
240 |