| Conditions | 4 |
| Paths | 5 |
| Total Lines | 55 |
| Code Lines | 28 |
| 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 |
||
| 81 | public function getTopEditsAllNamespaces(Project $project, User $user, $limit = 10) |
||
| 82 | { |
||
| 83 | // Set up cache. |
||
| 84 | $cacheKey = 'topedits.'.$project->getDatabaseName().'.'.$user->getCacheKey(). |
||
| 85 | 'all'.$limit; |
||
| 86 | if ($this->cache->hasItem($cacheKey)) { |
||
| 87 | return $this->cache->getItem($cacheKey)->get(); |
||
| 88 | } |
||
| 89 | |||
| 90 | $pageTable = $this->getTableName($project->getDatabaseName(), 'page'); |
||
| 91 | $revisionTable = $this->getTableName($project->getDatabaseName(), 'revision'); |
||
| 92 | $hasPageAssessments = $this->isLabs() && $project->hasPageAssessments(); |
||
| 93 | $pageAssessmentsTable = $this->getTableName($project->getDatabaseName(), 'page_assessments'); |
||
| 94 | $paSelect = $hasPageAssessments |
||
| 95 | ? ", ( |
||
| 96 | SELECT pa_class |
||
| 97 | FROM $pageAssessmentsTable |
||
| 98 | WHERE pa_page_id = e.page_id |
||
| 99 | LIMIT 1 |
||
| 100 | ) AS pa_class" |
||
| 101 | : ', NULL as pa_class'; |
||
| 102 | |||
| 103 | $sql = "SELECT c.page_namespace, e.page_title, c.count $paSelect |
||
| 104 | FROM |
||
| 105 | ( |
||
| 106 | SELECT b.page_namespace, b.rev_page, b.count |
||
| 107 | ,@rn := if(@ns = b.page_namespace, @rn + 1, 1) AS row_number |
||
| 108 | ,@ns := b.page_namespace AS dummy |
||
| 109 | FROM |
||
| 110 | ( |
||
| 111 | SELECT page_namespace, rev_page, count(rev_page) AS count |
||
| 112 | FROM $revisionTable |
||
| 113 | JOIN $pageTable ON page_id = rev_page |
||
| 114 | WHERE rev_user_text = :username |
||
| 115 | GROUP BY page_namespace, rev_page |
||
| 116 | ) AS b |
||
| 117 | JOIN (SELECT @ns := NULL, @rn := 0) AS vars |
||
| 118 | ORDER BY b.page_namespace ASC, b.count DESC |
||
| 119 | ) AS c |
||
| 120 | JOIN $pageTable e ON e.page_id = c.rev_page |
||
| 121 | WHERE c.row_number < $limit"; |
||
| 122 | $resultQuery = $this->getProjectsConnection()->prepare($sql); |
||
| 123 | $username = $user->getUsername(); |
||
| 124 | $resultQuery->bindParam('username', $username); |
||
| 125 | $resultQuery->execute(); |
||
| 126 | $results = $resultQuery->fetchAll(); |
||
| 127 | |||
| 128 | // Cache for 10 minutes, and return. |
||
| 129 | $cacheItem = $this->cache->getItem($cacheKey) |
||
| 130 | ->set($results) |
||
| 131 | ->expiresAfter(new DateInterval('PT10M')); |
||
| 132 | $this->cache->save($cacheItem); |
||
| 133 | |||
| 134 | return $results; |
||
| 135 | } |
||
| 136 | |||
| 151 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.