Conditions | 12 |
Paths | 256 |
Total Lines | 60 |
Code Lines | 37 |
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 |
||
56 | public function getList(array $options = array()) |
||
57 | { |
||
58 | $sql = 'SELECT au.*, u.status AS user_status, u.role_id AS user_role_id'; |
||
59 | |||
60 | if (!empty($options['count'])) { |
||
61 | $sql = 'SELECT COUNT(au.api_user_id)'; |
||
62 | } |
||
63 | |||
64 | $sql .= ' FROM module_api_user au |
||
65 | LEFT JOIN user u ON(au.user_id = u.user_id)'; |
||
66 | |||
67 | $conditions = array(); |
||
68 | |||
69 | if (isset($options['api_user_id'])) { |
||
70 | $sql .= ' WHERE au.api_user_id=?'; |
||
71 | $conditions[] = $options['api_user_id']; |
||
72 | } else { |
||
73 | $sql .= ' WHERE au.api_user_id IS NOT NULL'; |
||
74 | } |
||
75 | |||
76 | if (isset($options['user_id'])) { |
||
77 | $sql .= ' AND au.user_id=?'; |
||
78 | $conditions[] = $options['user_id']; |
||
79 | } |
||
80 | |||
81 | if (isset($options['secret'])) { |
||
82 | $sql .= ' AND au.secret=?'; |
||
83 | $conditions[] = $options['secret']; |
||
84 | } |
||
85 | |||
86 | if (isset($options['status'])) { |
||
87 | $sql .= ' AND au.status=?'; |
||
88 | $conditions[] = (int) $options['status']; |
||
89 | } |
||
90 | |||
91 | $allowed_order = array('asc', 'desc'); |
||
92 | $allowed_sort = array('name', 'api_user_id', 'user_id', 'created', 'modified', 'status'); |
||
93 | |||
94 | if (isset($options['sort']) |
||
95 | && in_array($options['sort'], $allowed_sort) |
||
96 | && isset($options['order']) |
||
97 | && in_array($options['order'], $allowed_order)) { |
||
98 | $sql .= " ORDER BY au.{$options['sort']} {$options['order']}"; |
||
99 | } else { |
||
100 | $sql .= ' ORDER BY au.created DESC'; |
||
101 | } |
||
102 | |||
103 | if (!empty($options['limit'])) { |
||
104 | $sql .= ' LIMIT ' . implode(',', array_map('intval', $options['limit'])); |
||
105 | } |
||
106 | |||
107 | if (empty($options['count'])) { |
||
108 | $fetch_options = array('index' => 'api_user_id', 'unserialize' => 'data'); |
||
109 | $result = $this->db->fetchAll($sql, $conditions, $fetch_options); |
||
110 | } else { |
||
111 | $result = (int) $this->db->fetchColumn($sql, $conditions); |
||
112 | } |
||
113 | |||
114 | return $result; |
||
115 | } |
||
116 | |||
150 |