| Conditions | 10 |
| Paths | 36 |
| Total Lines | 39 |
| Code Lines | 26 |
| 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 |
||
| 53 | public function getUserAverage($criteria = null) |
||
| 54 | { |
||
| 55 | $groupby = false; |
||
| 56 | $field = ''; |
||
| 57 | if (null !== $criteria && $criteria instanceof \CriteriaElement) { |
||
| 58 | if ('' != $criteria->groupby) { |
||
| 59 | $groupby = true; |
||
| 60 | $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
||
| 61 | } |
||
| 62 | } |
||
| 63 | $sql = "SELECT {$field} AVG(rating), count(*)"; |
||
| 64 | $sql .= " FROM {$this->table}"; |
||
| 65 | if (null !== $criteria && $criteria instanceof \CriteriaElement) { |
||
| 66 | $sql .= ' ' . $criteria->renderWhere(); |
||
|
|
|||
| 67 | if ('' != $criteria->groupby) { |
||
| 68 | $sql .= $criteria->getGroupby(); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | $result = $this->db->query($sql); |
||
| 72 | if (!$result) { |
||
| 73 | return 0; |
||
| 74 | } |
||
| 75 | if (false === $groupby) { |
||
| 76 | [$average, $count] = $this->db->fetchRow($result); |
||
| 77 | |||
| 78 | return [ |
||
| 79 | 'avg' => $average, |
||
| 80 | 'count' => $count, |
||
| 81 | ]; |
||
| 82 | } |
||
| 83 | $ret = []; |
||
| 84 | while (list($id, $average, $count) = $this->db->fetchRow($result)) { |
||
| 85 | $ret[$id] = [ |
||
| 86 | 'avg' => $average, |
||
| 87 | 'count' => $count, |
||
| 88 | ]; |
||
| 89 | } |
||
| 90 | |||
| 91 | return $ret; |
||
| 92 | } |
||
| 94 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.