| Conditions | 11 |
| Paths | 128 |
| Total Lines | 55 |
| Code Lines | 33 |
| 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 |
||
| 82 | public function getList(array $options = array()) |
||
| 83 | { |
||
| 84 | $sql = 'SELECT *'; |
||
| 85 | |||
| 86 | if (!empty($options['count'])) { |
||
| 87 | $sql = 'SELECT COUNT(box_id)'; |
||
| 88 | } |
||
| 89 | |||
| 90 | $sql .= ' FROM module_packer_boxes WHERE box_id IS NOT NULL'; |
||
| 91 | |||
| 92 | $conditions = array(); |
||
| 93 | |||
| 94 | if (isset($options['name'])) { |
||
| 95 | $sql .= ' AND name=?'; |
||
| 96 | $conditions[] = $options['name']; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (isset($options['status'])) { |
||
| 100 | $sql .= ' AND status=?'; |
||
| 101 | $conditions[] = (int) $options['status']; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (isset($options['shipping_method'])) { |
||
| 105 | $sql .= ' AND shipping_method = ?'; |
||
| 106 | $conditions[] = $options['shipping_method']; |
||
| 107 | } |
||
| 108 | |||
| 109 | $allowed_order = array('asc', 'desc'); |
||
| 110 | |||
| 111 | $allowed_sort = array( |
||
| 112 | 'name', 'status', 'shipping_method', 'outer_width', |
||
| 113 | 'outer_length', 'outer_depth', 'empty_weight', 'inner_width', |
||
| 114 | 'inner_width', 'inner_length', 'inner_depth', 'max_weight', |
||
| 115 | 'weight_unit', 'size_unit' |
||
| 116 | ); |
||
| 117 | |||
| 118 | if (isset($options['sort']) |
||
| 119 | && in_array($options['sort'], $allowed_sort) |
||
| 120 | && isset($options['order']) |
||
| 121 | && in_array($options['order'], $allowed_order)) { |
||
| 122 | $sql .= " ORDER BY {$options['sort']} {$options['order']}"; |
||
| 123 | } else { |
||
| 124 | $sql .= ' ORDER BY box_id DESC'; |
||
| 125 | } |
||
| 126 | |||
| 127 | if (!empty($options['limit'])) { |
||
| 128 | $sql .= ' LIMIT ' . implode(',', array_map('intval', $options['limit'])); |
||
| 129 | } |
||
| 130 | |||
| 131 | if (empty($options['count'])) { |
||
| 132 | return $this->db->fetchAll($sql, $conditions, array('index' => 'box_id')); |
||
| 133 | } |
||
| 134 | |||
| 135 | return (int) $this->db->fetchColumn($sql, $conditions); |
||
| 136 | } |
||
| 137 | |||
| 166 |