| Conditions | 11 |
| Paths | 18 |
| Total Lines | 45 |
| Code Lines | 15 |
| 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 |
||
| 19 | private function getGameSubmissionQuery($user_id = null, $last_timestamp = null, $action = null, $done = null) { |
||
| 20 | |||
| 21 | $query = "SELECT |
||
| 22 | game.game_id, |
||
| 23 | game.game_name, |
||
| 24 | game_submitinfo.timestamp, |
||
| 25 | game_submitinfo.timestamp as date, |
||
| 26 | game_submitinfo.submit_text, |
||
| 27 | game_submitinfo.game_submitinfo_id, |
||
| 28 | game_submitinfo.game_done, |
||
| 29 | users.user_id, |
||
| 30 | users.userid, |
||
| 31 | users.email, |
||
| 32 | users.join_date, |
||
| 33 | users.karma, |
||
| 34 | users.show_email, |
||
| 35 | users.avatar_ext, |
||
| 36 | (SELECT COUNT(*) FROM game_submitinfo |
||
| 37 | WHERE game_submitinfo.user_id = users.user_id) AS user_subm_count, |
||
| 38 | (SELECT COUNT(*) FROM comments |
||
| 39 | WHERE comments.user_id = users.user_id) AS user_comment_count |
||
| 40 | FROM game_submitinfo |
||
| 41 | LEFT JOIN game ON (game_submitinfo.game_id = game.game_id) |
||
| 42 | LEFT JOIN users ON (game_submitinfo.user_id = users.user_id)"; |
||
| 43 | |||
| 44 | if (isset($done) and $done == "1") { |
||
| 45 | $query .= " WHERE game_done = '1'"; |
||
| 46 | } elseif (isset($done) and $done == "2") { |
||
| 47 | $query .= " WHERE game_done <> '1'"; |
||
| 48 | } else { |
||
| 49 | $query .= " WHERE ( game_done <> '1' or game_done = '1')"; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (isset($user_id) and $user_id <> '') { |
||
| 53 | $query .= " AND users.user_id = $user_id"; |
||
| 54 | } |
||
| 55 | |||
| 56 | if (isset($action) and $action=="autoload") { |
||
| 57 | $query .= " AND game_submitinfo.timestamp < $last_timestamp "; |
||
| 58 | } elseif (isset($action) and $action=="search") { |
||
| 59 | $query .= " AND game_submitinfo.timestamp <= $last_timestamp "; |
||
| 60 | } |
||
| 61 | |||
| 62 | $query .= " ORDER BY game_submitinfo.timestamp DESC LIMIT 10"; |
||
| 63 | return $query; |
||
| 64 | } |
||
| 227 |