Conditions | 13 |
Paths | 320 |
Total Lines | 58 |
Code Lines | 30 |
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 |
||
71 | public function getUploads($data = array()) |
||
72 | { |
||
73 | $sql = " |
||
74 | SELECT * |
||
75 | FROM upload |
||
76 | "; |
||
77 | |||
78 | $implode = array(); |
||
79 | |||
80 | if (!empty($data['filter_name'])) { |
||
81 | $implode[] = "name LIKE '" . $this->db->escape($data['filter_name']) . "%'"; |
||
82 | } |
||
83 | |||
84 | if (!empty($data['filter_filename'])) { |
||
85 | $implode[] = "filename LIKE '" . $this->db->escape($data['filter_filename']) . "%'"; |
||
86 | } |
||
87 | |||
88 | if (!empty($data['filter_date_added'])) { |
||
89 | $implode[] = "date_added = '" . $this->db->escape($data['filter_date_added']) . "%'"; |
||
90 | } |
||
91 | |||
92 | if ($implode) { |
||
93 | $sql .= " WHERE " . implode(" AND ", $implode); |
||
94 | } |
||
95 | |||
96 | $sort_data = array( |
||
97 | 'name', |
||
98 | 'filename', |
||
99 | 'date_added' |
||
100 | ); |
||
101 | |||
102 | if (isset($data['sort']) && in_array($data['sort'], $sort_data)) { |
||
103 | $sql .= " ORDER BY " . $data['sort']; |
||
104 | } else { |
||
105 | $sql .= " ORDER BY date_added"; |
||
106 | } |
||
107 | |||
108 | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
||
109 | $sql .= " DESC"; |
||
110 | } else { |
||
111 | $sql .= " ASC"; |
||
112 | } |
||
113 | |||
114 | if (isset($data['start']) || isset($data['limit'])) { |
||
115 | if ($data['start'] < 0) { |
||
116 | $data['start'] = 0; |
||
117 | } |
||
118 | |||
119 | if ($data['limit'] < 1) { |
||
120 | $data['limit'] = 20; |
||
121 | } |
||
122 | |||
123 | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
||
124 | } |
||
125 | |||
126 | $query = $this->db->query($sql); |
||
127 | |||
128 | return $query->rows; |
||
129 | } |
||
161 |
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.