| Conditions | 2 |
| Paths | 2 |
| Total Lines | 76 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 55 | private function getUserDetail($userId) |
||
| 56 | { |
||
| 57 | $database = gGetDb(); |
||
| 58 | |||
| 59 | $user = User::getById($userId, $database); |
||
| 60 | if ($user == false) { |
||
| 61 | return BootstrapSkin::displayAlertBox("User not found", "alert-error", "Error", true, false, true); |
||
| 62 | } |
||
| 63 | |||
| 64 | global $smarty; |
||
| 65 | |||
| 66 | $activitySummary = $database->prepare(<<<SQL |
||
| 67 | SELECT COALESCE(closes.mail_desc, log.action) AS action, COUNT(*) AS count |
||
| 68 | FROM log |
||
| 69 | INNER JOIN user ON log.user = user.id |
||
| 70 | LEFT JOIN closes ON log.action = closes.closes |
||
| 71 | WHERE user.username = :username |
||
| 72 | GROUP BY action; |
||
| 73 | SQL |
||
| 74 | ); |
||
| 75 | $activitySummary->execute(array(":username" => $user->getUsername())); |
||
|
|
|||
| 76 | $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); |
||
| 77 | |||
| 78 | $smarty->assign("user", $user); |
||
| 79 | $smarty->assign("activity", $activitySummaryData); |
||
| 80 | |||
| 81 | $usersCreatedQuery = $database->prepare(<<<SQL |
||
| 82 | SELECT log.timestamp time, request.name name, request.id id |
||
| 83 | FROM log |
||
| 84 | INNER JOIN request ON (request.id = log.objectid and log.objecttype = 'Request') |
||
| 85 | INNER JOIN user ON log.user = user.id |
||
| 86 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
||
| 87 | WHERE user.username = :username |
||
| 88 | AND log.action LIKE 'Closed %' |
||
| 89 | AND (emailtemplate.oncreated = '1' OR log.action = 'Closed custom-y') |
||
| 90 | ORDER BY log.timestamp; |
||
| 91 | SQL |
||
| 92 | ); |
||
| 93 | $usersCreatedQuery->execute(array(":username" => $user->getUsername())); |
||
| 94 | $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
||
| 95 | $smarty->assign("created", $usersCreated); |
||
| 96 | |||
| 97 | $usersNotCreatedQuery = $database->prepare(<<<SQL |
||
| 98 | SELECT log.timestamp time, request.name name, request.id id |
||
| 99 | FROM log |
||
| 100 | JOIN request ON request.id = log.objectid and log.objecttype = 'Request' |
||
| 101 | JOIN user ON log.user = user.id |
||
| 102 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
||
| 103 | WHERE user.username = :username |
||
| 104 | AND log.action LIKE 'Closed %' |
||
| 105 | AND (emailtemplate.oncreated = '0' OR log.action = 'Closed custom-n' OR log.action = 'Closed 0') |
||
| 106 | ORDER BY log.timestamp; |
||
| 107 | SQL |
||
| 108 | ); |
||
| 109 | $usersNotCreatedQuery->execute(array(":username" => $user->getUsername())); |
||
| 110 | $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
||
| 111 | $smarty->assign("notcreated", $usersNotCreated); |
||
| 112 | |||
| 113 | $accountLogQuery = $database->prepare(<<<SQL |
||
| 114 | SELECT |
||
| 115 | user.username as log_user, |
||
| 116 | log.action as log_action, |
||
| 117 | log.timestamp as log_time, |
||
| 118 | log.comment as log_cmt |
||
| 119 | FROM log |
||
| 120 | INNER JOIN user ON user.id = log.user |
||
| 121 | WHERE log.objectid = :userid |
||
| 122 | AND log.objecttype = 'User' |
||
| 123 | AND log.action IN ('Approved','Suspended','Declined','Promoted','Demoted','Renamed','Prefchange'); |
||
| 124 | SQL |
||
| 125 | ); |
||
| 126 | $accountLogQuery->execute(array(":userid" => $user->getId())); |
||
| 127 | $accountLog = $accountLogQuery->fetchAll(PDO::FETCH_ASSOC); |
||
| 128 | $smarty->assign("accountlog", $accountLog); |
||
| 129 | |||
| 130 | return $smarty->fetch("statistics/userdetail.tpl"); |
||
| 131 | } |
||
| 138 |