| Conditions | 11 |
| Paths | 385 |
| Total Lines | 99 |
| Code Lines | 61 |
| 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 |
||
| 152 | public function getPagesCreated(Project $project, User $user, $namespace, $redirects) |
||
| 153 | { |
||
| 154 | $username = $user->getUsername(); |
||
| 155 | |||
| 156 | $cacheKey = 'pages.' . $project->getDatabaseName() . '.' |
||
| 157 | . $username . '.' . $namespace . '.' . $redirects; |
||
| 158 | if ($this->cache->hasItem($cacheKey)) { |
||
| 159 | return $this->cache->getItem($cacheKey)->get(); |
||
| 160 | } |
||
| 161 | $this->stopwatch->start($cacheKey, 'XTools'); |
||
| 162 | |||
| 163 | $dbName = $project->getDatabaseName(); |
||
| 164 | $projectRepo = $project->getRepository(); |
||
| 165 | |||
| 166 | $pageTable = $projectRepo->getTableName($dbName, 'page'); |
||
| 167 | $pageAssessmentsTable = $projectRepo->getTableName($dbName, 'page_assessments'); |
||
| 168 | $revisionTable = $projectRepo->getTableName($dbName, 'revision'); |
||
| 169 | $archiveTable = $projectRepo->getTableName($dbName, 'archive'); |
||
| 170 | $logTable = $projectRepo->getTableName($dbName, 'logging', 'userindex'); |
||
| 171 | |||
| 172 | $userId = $user->getId($project); |
||
| 173 | |||
| 174 | $namespaceConditionArc = ''; |
||
| 175 | $namespaceConditionRev = ''; |
||
| 176 | |||
| 177 | if ($namespace != 'all') { |
||
| 178 | $namespaceConditionRev = " AND page_namespace = '".intval($namespace)."' "; |
||
| 179 | $namespaceConditionArc = " AND ar_namespace = '".intval($namespace)."' "; |
||
| 180 | } |
||
| 181 | |||
| 182 | $redirectCondition = ''; |
||
| 183 | |||
| 184 | if ($redirects == 'onlyredirects') { |
||
| 185 | $redirectCondition = " AND page_is_redirect = '1' "; |
||
| 186 | } elseif ($redirects == 'noredirects') { |
||
| 187 | $redirectCondition = " AND page_is_redirect = '0' "; |
||
| 188 | } |
||
| 189 | |||
| 190 | if ($userId == 0) { // IP Editor or undefined username. |
||
| 191 | $whereRev = " rev_user_text = '$username' AND rev_user = '0' "; |
||
| 192 | $whereArc = " ar_user_text = '$username' AND ar_user = '0' "; |
||
| 193 | $having = " rev_user_text = '$username' "; |
||
| 194 | } else { |
||
| 195 | $whereRev = " rev_user = '$userId' AND rev_timestamp > 1 "; |
||
| 196 | $whereArc = " ar_user = '$userId' AND ar_timestamp > 1 "; |
||
| 197 | $having = " rev_user = '$userId' "; |
||
| 198 | } |
||
| 199 | |||
| 200 | $hasPageAssessments = $this->isLabs() && $project->hasPageAssessments(); |
||
| 201 | $paSelects = $hasPageAssessments ? ', pa_class, pa_importance, pa_page_revision' : ''; |
||
| 202 | $paSelectsArchive = $hasPageAssessments ? |
||
| 203 | ', NULL AS pa_class, NULL AS pa_page_id, NULL AS pa_page_revision' |
||
| 204 | : ''; |
||
| 205 | $paJoin = $hasPageAssessments ? "LEFT JOIN $pageAssessmentsTable ON rev_page = pa_page_id" : ''; |
||
| 206 | |||
| 207 | $sql = " |
||
| 208 | (SELECT DISTINCT page_namespace AS namespace, 'rev' AS type, page_title AS page_title, |
||
| 209 | page_len, page_is_redirect, rev_timestamp AS rev_timestamp, |
||
| 210 | rev_user, rev_user_text AS username, rev_len, rev_id $paSelects |
||
| 211 | FROM $pageTable |
||
| 212 | JOIN $revisionTable ON page_id = rev_page |
||
| 213 | $paJoin |
||
| 214 | WHERE $whereRev AND rev_parent_id = '0' $namespaceConditionRev $redirectCondition |
||
| 215 | " . ($hasPageAssessments ? 'GROUP BY rev_page' : '') . " |
||
| 216 | ) |
||
| 217 | |||
| 218 | UNION |
||
| 219 | |||
| 220 | (SELECT a.ar_namespace AS namespace, 'arc' AS type, a.ar_title AS page_title, |
||
| 221 | 0 AS page_len, '0' AS page_is_redirect, MIN(a.ar_timestamp) AS rev_timestamp, |
||
| 222 | a.ar_user AS rev_user, a.ar_user_text AS username, a.ar_len AS rev_len, |
||
| 223 | a.ar_rev_id AS rev_id $paSelectsArchive |
||
| 224 | FROM $archiveTable a |
||
| 225 | JOIN |
||
| 226 | ( |
||
| 227 | SELECT b.ar_namespace, b.ar_title |
||
| 228 | FROM $archiveTable AS b |
||
| 229 | LEFT JOIN $logTable ON log_namespace = b.ar_namespace AND log_title = b.ar_title |
||
| 230 | AND log_user = b.ar_user AND (log_action = 'move' OR log_action = 'move_redir') |
||
| 231 | WHERE $whereArc AND b.ar_parent_id = '0' $namespaceConditionArc AND log_action IS NULL |
||
| 232 | ) AS c ON c.ar_namespace= a.ar_namespace AND c.ar_title = a.ar_title |
||
| 233 | GROUP BY a.ar_namespace, a.ar_title |
||
| 234 | HAVING $having |
||
| 235 | ) |
||
| 236 | "; |
||
| 237 | |||
| 238 | $resultQuery = $this->getProjectsConnection()->prepare($sql); |
||
| 239 | $resultQuery->execute(); |
||
| 240 | $result = $resultQuery->fetchAll(); |
||
| 241 | |||
| 242 | // Cache for 10 minutes, and return. |
||
|
1 ignored issue
–
show
|
|||
| 243 | $cacheItem = $this->cache->getItem($cacheKey) |
||
| 244 | ->set($result) |
||
| 245 | ->expiresAfter(new DateInterval('PT10M')); |
||
| 246 | $this->cache->save($cacheItem); |
||
| 247 | $this->stopwatch->stop($cacheKey); |
||
| 248 | |||
| 249 | return $result; |
||
| 250 | } |
||
| 251 | |||
| 263 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.