| Conditions | 8 |
| Paths | 10 |
| Total Lines | 112 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 61 | protected function detail() |
||
| 62 | { |
||
| 63 | $userId = WebRequest::getInt('user'); |
||
| 64 | if ($userId === null) { |
||
| 65 | throw new ApplicationLogicException("User not found"); |
||
| 66 | } |
||
| 67 | |||
| 68 | $database = $this->getDatabase(); |
||
| 69 | |||
| 70 | $user = User::getById($userId, $database); |
||
| 71 | if ($user == false) { |
||
|
|
|||
| 72 | throw new ApplicationLogicException('User not found'); |
||
| 73 | } |
||
| 74 | |||
| 75 | |||
| 76 | $activitySummary = $database->prepare(<<<SQL |
||
| 77 | SELECT COALESCE(closes.mail_desc, log.action) AS action, COUNT(*) AS count |
||
| 78 | FROM log |
||
| 79 | INNER JOIN user ON log.user = user.id |
||
| 80 | LEFT JOIN closes ON log.action = closes.closes |
||
| 81 | WHERE user.username = :username |
||
| 82 | GROUP BY action; |
||
| 83 | SQL |
||
| 84 | ); |
||
| 85 | $activitySummary->execute(array(":username" => $user->getUsername())); |
||
| 86 | $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); |
||
| 87 | |||
| 88 | $this->assign("user", $user); |
||
| 89 | $this->assign("activity", $activitySummaryData); |
||
| 90 | |||
| 91 | $usersCreatedQuery = $database->prepare(<<<SQL |
||
| 92 | SELECT log.timestamp time, request.name name, request.id id |
||
| 93 | FROM log |
||
| 94 | INNER JOIN request ON (request.id = log.objectid AND log.objecttype = 'Request') |
||
| 95 | INNER JOIN user ON log.user = user.id |
||
| 96 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
||
| 97 | WHERE user.username = :username |
||
| 98 | AND log.action LIKE 'Closed %' |
||
| 99 | AND (emailtemplate.defaultaction = :created OR log.action = 'Closed custom-y') |
||
| 100 | ORDER BY log.timestamp; |
||
| 101 | SQL |
||
| 102 | ); |
||
| 103 | $usersCreatedQuery->execute(array(":username" => $user->getUsername(), ':created' => EmailTemplate::ACTION_CREATED)); |
||
| 104 | $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
||
| 105 | $this->assign("created", $usersCreated); |
||
| 106 | |||
| 107 | $usersNotCreatedQuery = $database->prepare(<<<SQL |
||
| 108 | SELECT log.timestamp time, request.name name, request.id id |
||
| 109 | FROM log |
||
| 110 | JOIN request ON request.id = log.objectid AND log.objecttype = 'Request' |
||
| 111 | JOIN user ON log.user = user.id |
||
| 112 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
||
| 113 | WHERE user.username = :username |
||
| 114 | AND log.action LIKE 'Closed %' |
||
| 115 | AND (emailtemplate.defaultaction = :created OR log.action = 'Closed custom-n' OR log.action = 'Closed 0') |
||
| 116 | ORDER BY log.timestamp; |
||
| 117 | SQL |
||
| 118 | ); |
||
| 119 | $usersNotCreatedQuery->execute(array(":username" => $user->getUsername(), ':created' => EmailTemplate::ACTION_NOT_CREATED)); |
||
| 120 | $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
||
| 121 | $this->assign("notcreated", $usersNotCreated); |
||
| 122 | |||
| 123 | /** @var Log[] $logs */ |
||
| 124 | $logs = LogSearchHelper::get($database) |
||
| 125 | ->byObjectType('User') |
||
| 126 | ->byObjectId($user->getId()) |
||
| 127 | ->getRecordCount($logCount) |
||
| 128 | ->fetch(); |
||
| 129 | |||
| 130 | if ($logCount === 0) { |
||
| 131 | $this->assign('accountlog', array()); |
||
| 132 | } |
||
| 133 | else { |
||
| 134 | list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration()); |
||
| 135 | |||
| 136 | $this->assign("accountlog", $logData); |
||
| 137 | $this->assign("users", $users); |
||
| 138 | } |
||
| 139 | |||
| 140 | $currentUser = User::getCurrent($database); |
||
| 141 | $this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class)); |
||
| 142 | $this->assign('canDecline', $this->barrierTest('decline', $currentUser, PageUserManagement::class)); |
||
| 143 | $this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class)); |
||
| 144 | $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser, PageUserManagement::class)); |
||
| 145 | $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser, PageUserManagement::class)); |
||
| 146 | $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser, PageUserManagement::class)); |
||
| 147 | |||
| 148 | $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
||
| 149 | $this->assign('oauth', $oauth); |
||
| 150 | |||
| 151 | if ($user->getForceIdentified() === null) { |
||
| 152 | $idVerifier = new IdentificationVerifier($this->getHttpHelper(), $this->getSiteConfiguration(), $this->getDatabase()); |
||
| 153 | $this->assign('identificationStatus', $idVerifier->isUserIdentified($user->getOnWikiName()) ? 'detected' : 'missing'); |
||
| 154 | } |
||
| 155 | else { |
||
| 156 | $this->assign('identificationStatus', $user->getForceIdentified() == 1 ? 'forced-on' : 'forced-off'); |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($oauth->isFullyLinked()) { |
||
| 160 | $this->assign('identity', $oauth->getIdentity(true)); |
||
| 161 | $this->assign('identityExpired', $oauth->identityExpired()); |
||
| 162 | } |
||
| 163 | |||
| 164 | $this->assign('statsPageTitle', 'Account Creation Tool users'); |
||
| 165 | |||
| 166 | // FIXME: domains! |
||
| 167 | /** @var Domain $domain */ |
||
| 168 | $domain = Domain::getById(1, $this->getDatabase()); |
||
| 169 | $this->assign('mediawikiScriptPath', $domain->getWikiArticlePath()); |
||
| 170 | |||
| 171 | $this->setHtmlTitle('{$user->getUsername()|escape} :: Users :: Statistics'); |
||
| 172 | $this->setTemplate("statistics/userdetail.tpl"); |
||
| 173 | } |
||
| 175 |