| Conditions | 14 |
| Paths | 320 |
| Total Lines | 65 |
| Code Lines | 32 |
| 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 |
||
| 88 | public function getReviews($data = array()) |
||
| 89 | { |
||
| 90 | $sql = " |
||
| 91 | SELECT r.review_id, |
||
| 92 | pd.name, |
||
| 93 | r.author, |
||
| 94 | r.rating, |
||
| 95 | r.status, |
||
| 96 | r.date_added |
||
| 97 | FROM review r |
||
| 98 | LEFT JOIN product_description pd ON (r.product_id = pd.product_id) |
||
| 99 | WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' |
||
| 100 | "; |
||
| 101 | |||
| 102 | if (!empty($data['filter_product'])) { |
||
| 103 | $sql .= " AND pd.name LIKE '" . $this->db->escape($data['filter_product']) . "%'"; |
||
| 104 | } |
||
| 105 | |||
| 106 | if (!empty($data['filter_author'])) { |
||
| 107 | $sql .= " AND r.author LIKE '" . $this->db->escape($data['filter_author']) . "%'"; |
||
| 108 | } |
||
| 109 | |||
| 110 | if (isset($data['filter_status']) && !is_null($data['filter_status'])) { |
||
| 111 | $sql .= " AND r.status = '" . (int)$data['filter_status'] . "'"; |
||
| 112 | } |
||
| 113 | |||
| 114 | if (!empty($data['filter_date_added'])) { |
||
| 115 | $sql .= " AND DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')"; |
||
| 116 | } |
||
| 117 | |||
| 118 | $sort_data = array( |
||
| 119 | 'pd.name', |
||
| 120 | 'r.author', |
||
| 121 | 'r.rating', |
||
| 122 | 'r.status', |
||
| 123 | 'r.date_added' |
||
| 124 | ); |
||
| 125 | |||
| 126 | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
||
| 127 | $sql .= " ORDER BY " . $data['sort']; |
||
| 128 | } else { |
||
| 129 | $sql .= " ORDER BY r.date_added"; |
||
| 130 | } |
||
| 131 | |||
| 132 | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
||
| 133 | $sql .= " DESC"; |
||
| 134 | } else { |
||
| 135 | $sql .= " ASC"; |
||
| 136 | } |
||
| 137 | |||
| 138 | if (isset($data['start']) || isset($data['limit'])) { |
||
| 139 | if ($data['start'] < 0) { |
||
| 140 | $data['start'] = 0; |
||
| 141 | } |
||
| 142 | |||
| 143 | if ($data['limit'] < 1) { |
||
| 144 | $data['limit'] = 20; |
||
| 145 | } |
||
| 146 | |||
| 147 | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
||
| 148 | } |
||
| 149 | |||
| 150 | $query = $this->db->query($sql); |
||
| 151 | |||
| 152 | return $query->rows; |
||
| 153 | } |
||
| 192 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.