Conditions | 10 |
Paths | 21 |
Total Lines | 45 |
Code Lines | 22 |
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 |
||
61 | public function getUrlAaliases($data = array()) |
||
62 | { |
||
63 | if ($data) { |
||
64 | $sql = " |
||
65 | SELECT * |
||
66 | FROM `url_alias` ua |
||
67 | "; |
||
68 | |||
69 | $sort_data = array('ua.query', 'ua.keyword'); |
||
70 | |||
71 | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
||
72 | $sql .= " ORDER BY " . $data['sort']; |
||
73 | } else { |
||
74 | $sql .= " ORDER BY ua.query"; |
||
75 | } |
||
76 | |||
77 | if (isset($data['order']) && ($data['order'] == 'ASC')) { |
||
78 | $sql .= " ASC"; |
||
79 | } else { |
||
80 | $sql .= " DESC"; |
||
81 | } |
||
82 | |||
83 | if (isset($data['start']) || isset($data['limit'])) { |
||
84 | if ($data['start'] < 0) { |
||
85 | $data['start'] = 0; |
||
86 | } |
||
87 | |||
88 | if ($data['limit'] < 1) { |
||
89 | $data['limit'] = 20; |
||
90 | } |
||
91 | |||
92 | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
||
93 | } |
||
94 | |||
95 | $query = $this->db->query($sql); |
||
96 | |||
97 | return $query->rows; |
||
98 | } else { |
||
99 | $query = $this->db->query(" |
||
100 | SELECT * |
||
101 | FROM `url_alias` ua |
||
102 | ORDER BY ua.query |
||
103 | "); |
||
104 | |||
105 | return $query->rows; |
||
106 | } |
||
120 |
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.