Conditions | 7 |
Paths | 15 |
Total Lines | 136 |
Code Lines | 116 |
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 |
||
148 | public function getUserRateSave($tables, $language, $t) |
||
149 | { |
||
150 | $ret = $this->pc->getPhpCodeCommentLine('Security Check', '', $t); |
||
151 | $xoopsSecurityCheck = $this->xc->getXcXoopsSecurityCheck(); |
||
152 | $securityError = $this->xc->getXcXoopsSecurityErrors(); |
||
153 | $implode = $this->pc->getPhpCodeImplode(',', $securityError); |
||
154 | $redirectError = $this->xc->getXcRedirectHeader('index', '', '3', $implode, true, $t . "\t"); |
||
155 | $ret .= $this->pc->getPhpCodeConditions($xoopsSecurityCheck, '', '', $redirectError, false, $t); |
||
156 | |||
157 | $ret .= $this->xc->getXcXoopsRequest('rating', 'rating', '0', 'Int', false, $t); |
||
158 | $ret .= $this->xc->getXcEqualsOperator('$itemid', '0','', $t); |
||
159 | $ret .= $this->xc->getXcEqualsOperator('$redir ', "\$_SERVER['HTTP_REFERER']",'', $t); |
||
160 | foreach ($tables as $table) { |
||
161 | $tableName = $table->getVar('table_name'); |
||
162 | $stuTableName = mb_strtoupper($tableName); |
||
163 | if (1 == $table->getVar('table_rate')) { |
||
164 | $fields = $this->getTableFields($table->getVar('table_mid'), $table->getVar('table_id')); |
||
165 | $fieldId = ''; |
||
166 | foreach (array_keys($fields) as $f) { |
||
167 | if (0 == $f) { |
||
168 | $fieldId = $fields[$f]->getVar('field_name'); |
||
169 | } |
||
170 | } |
||
171 | $contIf = $this->xc->getXcXoopsRequest('itemid', $fieldId, '0', 'Int', false, $t . "\t"); |
||
172 | $contIf .= $this->xc->getXcEqualsOperator('$redir', "'{$tableName}.php?op=show&{$fieldId}=' . \$itemid",'', $t . "\t"); |
||
173 | $const = $this->xc->getXcGetConstants('TABLE_' . $stuTableName); |
||
174 | $ret .= $this->pc->getPhpCodeConditions('$source', ' === ', $const, $contIf, false, $t); |
||
175 | } |
||
176 | } |
||
177 | |||
178 | $ret .= $this->pc->getPhpCodeBlankLine(); |
||
179 | $ret .= $this->pc->getPhpCodeCommentLine('Check permissions', '', $t); |
||
180 | $ret .= $this->xc->getXcEqualsOperator('$rate_allowed', 'false','', $t); |
||
181 | $xUser = $this->pc->getPhpCodeGlobals('xoopsUser'); |
||
182 | $ret .= $this->pc->getPhpCodeTernaryOperator('groups', '(isset(' . $xUser . ') && is_object(' . $xUser . '))', $xUser . '->getGroups()', 'XOOPS_GROUP_ANONYMOUS', "\t\t"); |
||
183 | $contIf = $this->xc->getXcEqualsOperator('$rate_allowed', 'true','', $t . "\t\t"); |
||
184 | $contIf .= $this->getSimpleString('break;', $t . "\t\t"); |
||
185 | $cond = 'XOOPS_GROUP_ADMIN == $group || in_array($group, $helper->getConfig(\'ratingbar_groups\'))'; |
||
186 | $contFe = $this->pc->getPhpCodeConditions($cond, '', '', $contIf, false, $t . "\t"); |
||
187 | $ret .= $this->pc->getPhpCodeForeach('groups', false, false, 'group', $contFe, $t); |
||
188 | $contIf = $this->xc->getXcRedirectHeader('index', '', '3', $language . 'RATING_NOPERM', true, $t . "\t"); |
||
189 | $ret .= $this->pc->getPhpCodeConditions('!$rate_allowed', '', '', $contIf, false, $t); |
||
190 | |||
191 | $ret .= $this->pc->getPhpCodeBlankLine(); |
||
192 | $ret .= $this->pc->getPhpCodeCommentLine('Check rating value', null, $t); |
||
193 | $cases = []; |
||
194 | $contIf = $this->xc->getXcRedirectHeader('index', '', '3', $language . 'RATING_VOTE_BAD', true, $t . "\t\t"); |
||
195 | $contIf .= $this->getSimpleString('exit;', $t . "\t\t"); |
||
196 | $const = $this->xc->getXcGetConstants('RATING_NONE'); |
||
197 | $cases[$const] = [$contIf]; |
||
198 | $contIf = $this->xc->getXcRedirectHeader('index', '', '3', $language . 'RATING_VOTE_BAD', true, $t . "\t\t\t"); |
||
199 | $contIf .= $this->getSimpleString('exit;', $t . "\t\t\t"); |
||
200 | $const = $this->xc->getXcGetConstants('RATING_LIKES'); |
||
201 | $cases[$const] = [$this->pc->getPhpCodeConditions('$rating > 1 || $rating < -1', '', '', $contIf, false, $t . "\t\t")]; |
||
202 | $const = $this->xc->getXcGetConstants('RATING_5STARS'); |
||
203 | $cases[$const] = [$this->pc->getPhpCodeConditions('$rating > 5 || $rating < 1', '', '', $contIf, false, $t . "\t\t")]; |
||
204 | $const = $this->xc->getXcGetConstants('RATING_10STARS'); |
||
205 | $cases[$const] = ''; |
||
206 | $const = $this->xc->getXcGetConstants('RATING_10NUM'); |
||
207 | $cases[$const] = [$this->pc->getPhpCodeConditions('$rating > 10 || $rating < 1', '', '', $contIf, false, $t . "\t\t")]; |
||
208 | $config = '(int)' . $this->xc->getXcGetConfig('ratingbars'); |
||
209 | $ret .= $this->xc->getXcSwitch($config, $cases, true, false, $t, false, true); |
||
210 | |||
211 | $ret .= $this->pc->getPhpCodeBlankLine(); |
||
212 | $ret .= $this->pc->getPhpCodeCommentLine('Get existing rating', null, $t); |
||
213 | $ret .= $this->xc->getXcEqualsOperator('$itemrating', '$ratingsHandler->getItemRating($itemid, $source)','', $t); |
||
214 | |||
215 | $ret .= $this->pc->getPhpCodeBlankLine(); |
||
216 | $ret .= $this->pc->getPhpCodeCommentLine('Set data rating', null, $t); |
||
217 | $contIf = $this->pc->getPhpCodeCommentLine('If yo want to avoid revoting then activate next line', null, $t . "\t"); |
||
218 | $contIf .= $t . "\t//" . $this->xc->getXcRedirectHeader('index', '', '3', $language . 'RATING_VOTE_BAD'); |
||
219 | $contIf .= $this->xc->getXcHandlerGet('ratings', "itemrating['id']",'Obj', 'ratingsHandler', false, $t . "\t"); |
||
220 | $contElse = $this->xc->getXcHandlerCreateObj('ratings', $t . "\t"); |
||
221 | $ret .= $this->pc->getPhpCodeConditions("\$itemrating['voted']", '', '', $contIf, $contElse, $t); |
||
222 | $ret .= $this->xc->getXcSetVarObj('ratings', 'rate_source', '$source', $t); |
||
223 | $ret .= $this->xc->getXcSetVarObj('ratings', 'rate_itemid', '$itemid', $t); |
||
224 | $ret .= $this->xc->getXcSetVarObj('ratings', 'rate_value', '$rating', $t); |
||
225 | $ret .= $this->xc->getXcSetVarObj('ratings', 'rate_uid', "\$itemrating['uid']", $t); |
||
226 | $ret .= $this->xc->getXcSetVarObj('ratings', 'rate_ip', "\$itemrating['ip']", $t); |
||
227 | $ret .= $this->xc->getXcSetVarObj('ratings', 'rate_date', 'time()', $t); |
||
228 | $ret .= $this->pc->getPhpCodeCommentLine('Insert Data', null, $t); |
||
229 | $insert = $this->xc->getXcHandlerInsert('ratings', 'ratings', 'Obj'); |
||
230 | $contIf = $this->pc->getPhpCodeUnset('ratingsObj', $t . "\t"); |
||
231 | |||
232 | $contIf .= $this->pc->getPhpCodeCommentLine('Calc average rating value', null, $t . "\t"); |
||
233 | $contIf .= $this->xc->getXcEqualsOperator('$nb_ratings ', '0','', $t . "\t"); |
||
234 | $contIf .= $this->xc->getXcEqualsOperator('$avg_rate_value', '0','', $t . "\t"); |
||
235 | $contIf .= $this->xc->getXcEqualsOperator('$current_rating', '0','', $t . "\t"); |
||
236 | $tableName = 'ratings'; |
||
237 | $ucfTableName = ucfirst($tableName); |
||
238 | $critName = 'cr' . $ucfTableName; |
||
239 | $contIf .= $this->xc->getXcCriteriaCompo($critName, $t . "\t"); |
||
240 | $crit = $this->xc->getXcCriteria('', "'rate_source'", '$source','',true); |
||
241 | $contIf .= $this->xc->getXcCriteriaAdd($critName, $crit, $t . "\t"); |
||
242 | $crit = $this->xc->getXcCriteria('', "'rate_itemid'", '$itemid','',true); |
||
243 | $contIf .= $this->xc->getXcCriteriaAdd($critName, $crit, $t . "\t"); |
||
244 | $contIf .= $this->xc->getXcHandlerCountClear($tableName . 'Count', $tableName, '$' . $critName, $t . "\t"); |
||
245 | $contIf .= $this->xc->getXcHandlerAllClear($tableName . 'All', $tableName, '$' . $critName, $t . "\t"); |
||
246 | $contFe = $this->xc->getXcEqualsOperator('$current_rating', "\$ratingsAll[\$i]->getVar('rate_value')",'+', $t . "\t\t"); |
||
247 | $contIf .= $this->pc->getPhpCodeForeach("{$tableName}All", true, false, 'i', $contFe, $t . "\t"); |
||
248 | $contIf .= $this->pc->getPhpCodeUnset($tableName . 'All', $t . "\t"); |
||
249 | $contIfInt = $this->xc->getXcEqualsOperator('$avg_rate_value', 'number_format($current_rating / $ratingsCount, 2)','', $t . "\t\t"); |
||
250 | $contIf .= $this->pc->getPhpCodeConditions('$ratingsCount', ' > ', '0', $contIfInt, false, $t . "\t"); |
||
251 | |||
252 | $contIf .= $this->pc->getPhpCodeCommentLine('Update related table', null, $t . "\t"); |
||
253 | foreach ($tables as $table) { |
||
254 | $tableName = $table->getVar('table_name'); |
||
255 | $tableFieldName = $table->getVar('table_fieldname'); |
||
256 | $stuTableName = mb_strtoupper($tableName); |
||
257 | if (1 == $table->getVar('table_rate')) { |
||
258 | $contIfInt = $this->xc->getXcEqualsOperator('$tableName', "'{$tableName}'",'', $t . "\t\t"); |
||
259 | $contIfInt .= $this->xc->getXcEqualsOperator('$fieldRatings', "'{$tableFieldName}_ratings'",'', $t . "\t\t"); |
||
260 | $contIfInt .= $this->xc->getXcEqualsOperator('$fieldVotes ', "'{$tableFieldName}_votes'",'', $t . "\t\t"); |
||
261 | $contIfInt .= $this->xc->getXcHandlerGetObj($tableName, 'itemid', $t . "\t\t"); |
||
262 | $contIfInt .= $this->xc->getXcSetVarObj($tableName, "{$tableFieldName}_ratings", '$avg_rate_value', $t . "\t\t"); |
||
263 | $contIfInt .= $this->xc->getXcSetVarObj($tableName, "{$tableFieldName}_votes", '$ratingsCount', $t . "\t\t"); |
||
264 | $insertInt = $this->xc->getXcHandlerInsert($tableName, $tableName, 'Obj'); |
||
265 | |||
266 | $insertOK = $this->xc->getXcRedirectHeader('$redir', '', '2', "{$language}RATING_VOTE_THANKS", false, $t . "\t\t\t"); |
||
267 | $insertErr = $this->xc->getXcRedirectHeader($tableName, '', '3', "{$language}RATING_ERROR1", true, $t . "\t\t\t"); |
||
268 | $contIfInt .= $this->pc->getPhpCodeConditions($insertInt, '', '', $insertOK, $insertErr, $t. "\t\t"); |
||
269 | $contIfInt .= $this->pc->getPhpCodeUnset($tableName . 'Obj', $t . "\t\t"); |
||
270 | $const = $this->xc->getXcGetConstants('TABLE_' . $stuTableName); |
||
271 | $contIf .= $this->pc->getPhpCodeConditions('$source', ' === ', $const, $contIfInt, false, $t . "\t"); |
||
272 | } |
||
273 | } |
||
274 | |||
275 | $contIf .= $this->pc->getPhpCodeBlankLine(); |
||
276 | $contIf .= $this->xc->getXcRedirectHeader('index', '', '2', "{$language}RATING_VOTE_THANKS", true, $t . "\t"); |
||
277 | $ret .= $this->pc->getPhpCodeConditions($insert, '', '', $contIf, false, $t); |
||
278 | |||
279 | $ret .= $this->pc->getPhpCodeCommentLine('Get Error', null, $t); |
||
280 | $ret .= $this->getSimpleString("echo 'Error: ' . \$ratingsObj->getHtmlErrors();", $t); |
||
281 | |||
282 | |||
283 | return $ret; |
||
284 | } |
||
317 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.