| Conditions | 8 |
| Paths | 10 |
| Total Lines | 111 |
| Code Lines | 79 |
| 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 |
||
| 62 | protected function detail() |
||
| 63 | { |
||
| 64 | $userId = WebRequest::getInt('user'); |
||
| 65 | if ($userId === null) { |
||
| 66 | throw new ApplicationLogicException("User not found"); |
||
| 67 | } |
||
| 68 | |||
| 69 | $database = $this->getDatabase(); |
||
| 70 | |||
| 71 | $user = User::getById($userId, $database); |
||
| 72 | if ($user == false) { |
||
|
|
|||
| 73 | throw new ApplicationLogicException('User not found'); |
||
| 74 | } |
||
| 75 | |||
| 76 | |||
| 77 | $activitySummary = $database->prepare(<<<SQL |
||
| 78 | SELECT COALESCE(closes.mail_desc, log.action) AS action, COUNT(*) AS count |
||
| 79 | FROM log |
||
| 80 | INNER JOIN user ON log.user = user.id |
||
| 81 | LEFT JOIN closes ON log.action = closes.closes |
||
| 82 | WHERE user.username = :username |
||
| 83 | GROUP BY action; |
||
| 84 | SQL |
||
| 85 | ); |
||
| 86 | $activitySummary->execute(array(":username" => $user->getUsername())); |
||
| 87 | $activitySummaryData = $activitySummary->fetchAll(PDO::FETCH_ASSOC); |
||
| 88 | |||
| 89 | $this->assign("user", $user); |
||
| 90 | $this->assign("activity", $activitySummaryData); |
||
| 91 | |||
| 92 | $usersCreatedQuery = $database->prepare(<<<SQL |
||
| 93 | SELECT log.timestamp time, request.name name, request.id id |
||
| 94 | FROM log |
||
| 95 | INNER JOIN request ON (request.id = log.objectid AND log.objecttype = 'Request') |
||
| 96 | INNER JOIN user ON log.user = user.id |
||
| 97 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
||
| 98 | WHERE user.username = :username |
||
| 99 | AND log.action LIKE 'Closed %' |
||
| 100 | AND (emailtemplate.defaultaction = :created OR log.action = 'Closed custom-y') |
||
| 101 | ORDER BY log.timestamp; |
||
| 102 | SQL |
||
| 103 | ); |
||
| 104 | $usersCreatedQuery->execute(array(":username" => $user->getUsername(), ':created' => EmailTemplate::ACTION_CREATED)); |
||
| 105 | $usersCreated = $usersCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
||
| 106 | $this->assign("created", $usersCreated); |
||
| 107 | |||
| 108 | $usersNotCreatedQuery = $database->prepare(<<<SQL |
||
| 109 | SELECT log.timestamp time, request.name name, request.id id |
||
| 110 | FROM log |
||
| 111 | JOIN request ON request.id = log.objectid AND log.objecttype = 'Request' |
||
| 112 | JOIN user ON log.user = user.id |
||
| 113 | LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action |
||
| 114 | WHERE user.username = :username |
||
| 115 | AND log.action LIKE 'Closed %' |
||
| 116 | AND (emailtemplate.defaultaction = :created OR log.action = 'Closed custom-n' OR log.action = 'Closed 0') |
||
| 117 | ORDER BY log.timestamp; |
||
| 118 | SQL |
||
| 119 | ); |
||
| 120 | $usersNotCreatedQuery->execute(array(":username" => $user->getUsername(), ':created' => EmailTemplate::ACTION_NOT_CREATED)); |
||
| 121 | $usersNotCreated = $usersNotCreatedQuery->fetchAll(PDO::FETCH_ASSOC); |
||
| 122 | $this->assign("notcreated", $usersNotCreated); |
||
| 123 | |||
| 124 | /** @var Log[] $logs */ |
||
| 125 | $logs = LogSearchHelper::get($database, Domain::getCurrent($database)->getId()) |
||
| 126 | ->byObjectType('User') |
||
| 127 | ->byObjectId($user->getId()) |
||
| 128 | ->getRecordCount($logCount) |
||
| 129 | ->fetch(); |
||
| 130 | |||
| 131 | if ($logCount === 0) { |
||
| 132 | $this->assign('accountlog', array()); |
||
| 133 | } |
||
| 134 | else { |
||
| 135 | list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration(), $this->getSecurityManager()); |
||
| 136 | |||
| 137 | $this->assign("accountlog", $logData); |
||
| 138 | $this->assign("users", $users); |
||
| 139 | } |
||
| 140 | |||
| 141 | $currentUser = User::getCurrent($database); |
||
| 142 | $this->assign('canApprove', $this->barrierTest('approve', $currentUser, PageUserManagement::class)); |
||
| 143 | $this->assign('canDeactivate', $this->barrierTest('deactivate', $currentUser, PageUserManagement::class)); |
||
| 144 | $this->assign('canRename', $this->barrierTest('rename', $currentUser, PageUserManagement::class)); |
||
| 145 | $this->assign('canEditUser', $this->barrierTest('editUser', $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 |