| Conditions | 2 |
| Paths | 2 |
| Total Lines | 62 |
| 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 |
||
| 145 | public function getAll($options = array()) |
||
| 146 | { |
||
| 147 | $sort = $options['sort']; |
||
| 148 | $direction = $options['direction']; |
||
| 149 | $page = $options['page']; |
||
| 150 | $perPage = $options['perPage']; |
||
| 151 | |||
| 152 | $stmt = $this->pdo->query(" |
||
| 153 | SELECT |
||
| 154 | id, |
||
| 155 | url, |
||
| 156 | SERVER, |
||
| 157 | GET, |
||
| 158 | ENV, |
||
| 159 | simple_url, |
||
| 160 | request_ts, |
||
| 161 | request_ts_micro, |
||
| 162 | request_date, |
||
| 163 | main_wt, |
||
| 164 | main_ct, |
||
| 165 | main_cpu, |
||
| 166 | main_mu, |
||
| 167 | main_pmu |
||
| 168 | FROM {$this->table} |
||
| 169 | ORDER BY request_ts DESC |
||
| 170 | ", PDO::FETCH_ASSOC); |
||
| 171 | |||
| 172 | $results = []; |
||
| 173 | foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { |
||
| 174 | $results[] = new Xhgui_Profile([ |
||
| 175 | '_id' => $row['id'], |
||
| 176 | 'meta' => [ |
||
| 177 | 'url' => $row['url'], |
||
| 178 | 'SERVER' => json_decode($row['SERVER'], true), |
||
| 179 | 'get' => json_decode($row['GET'], true), |
||
| 180 | 'env' => json_decode($row['ENV'], true), |
||
| 181 | 'simple_url' => $row['simple_url'], |
||
| 182 | 'request_ts' => $row['request_ts'], |
||
| 183 | 'request_ts_micro' => $row['request_ts_micro'], |
||
| 184 | 'request_date' => $row['request_date'], |
||
| 185 | ], |
||
| 186 | 'profile' => [ |
||
| 187 | 'main()' => [ |
||
| 188 | 'wt' => (int) $row['main_wt'], |
||
| 189 | 'ct' => (int) $row['main_ct'], |
||
| 190 | 'cpu' => (int) $row['main_cpu'], |
||
| 191 | 'mu' => (int) $row['main_mu'], |
||
| 192 | 'pmu' => (int) $row['main_pmu'], |
||
| 193 | ] |
||
| 194 | ] |
||
| 195 | ]); |
||
| 196 | } |
||
| 197 | |||
| 198 | return array( |
||
| 199 | 'results' => $results, |
||
| 200 | 'sort' => 'meta.request_ts', |
||
| 201 | 'direction' => 'desc', |
||
| 202 | 'page' => 1, |
||
| 203 | 'perPage' => count($results), |
||
| 204 | 'totalPages' => 1 |
||
| 205 | ); |
||
| 206 | } |
||
| 207 | |||
| 231 |