| Conditions | 7 |
| Paths | 15 |
| Total Lines | 148 |
| Code Lines | 83 |
| Lines | 8 |
| Ratio | 5.41 % |
| 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 |
||
| 49 | public function resultAction($project, $username) |
||
| 50 | { |
||
| 51 | |||
| 52 | $lh = $this->get("app.labs_helper"); |
||
| 53 | |||
| 54 | $lh->checkEnabled("adminscore"); |
||
| 55 | |||
| 56 | $username = ucfirst($username); |
||
| 57 | |||
| 58 | $projectData = ProjectRepository::getProject($project, $this->container); |
||
|
1 ignored issue
–
show
|
|||
| 59 | |||
| 60 | View Code Duplication | if (!$projectData->exists()) { |
|
| 61 | $this->addFlash("notice", ["invalid-project", $project]); |
||
| 62 | return $this->redirectToRoute("adminscore"); |
||
| 63 | } |
||
| 64 | |||
| 65 | $dbName = $projectData->getDatabaseName(); |
||
| 66 | $wikiName = $projectData->getDatabaseName(); |
||
| 67 | $url = $projectData->getUrl(); |
||
| 68 | |||
| 69 | $userTable = $lh->getTable("user", $dbName); |
||
| 70 | $pageTable = $lh->getTable("page", $dbName); |
||
| 71 | $loggingTable = $lh->getTable("logging", $dbName, "userindex"); |
||
| 72 | $revisionTable = $lh->getTable("revision", $dbName); |
||
| 73 | $archiveTable = $lh->getTable("archive", $dbName); |
||
| 74 | |||
| 75 | // MULTIPLIERS (to review) |
||
| 76 | $ACCT_AGE_MULT = 1.25; # 0 if = 365 jours |
||
| 77 | $EDIT_COUNT_MULT = 1.25; # 0 if = 10 000 |
||
|
1 ignored issue
–
show
|
|||
| 78 | $USER_PAGE_MULT = 0.1; # 0 if = |
||
| 79 | $PATROLS_MULT = 1; # 0 if = |
||
| 80 | $BLOCKS_MULT = 1.4; # 0 if = 10 |
||
|
1 ignored issue
–
show
|
|||
| 81 | $AFD_MULT = 1.15; |
||
| 82 | $RECENT_ACTIVITY_MULT = 0.9; # 0 if = |
||
| 83 | $AIV_MULT = 1.15; |
||
| 84 | $EDIT_SUMMARIES_MULT = 0.8; # 0 if = |
||
| 85 | $NAMESPACES_MULT = 1.0; # 0 if = |
||
| 86 | $PAGES_CREATED_LIVE_MULT = 1.4; # 0 if = |
||
| 87 | $PAGES_CREATED_ARCHIVE_MULT = 1.4; # 0 if = |
||
| 88 | $RPP_MULT = 1.15; # 0 if = |
||
| 89 | $USERRIGHTS_MULT = 0.75; # 0 if = |
||
| 90 | |||
| 91 | // Grab the connection to the replica database (which is separate from the above) |
||
| 92 | $conn = $this->get('doctrine')->getManager("replicas")->getConnection(); |
||
| 93 | |||
| 94 | // Prepare the query and execute |
||
| 95 | $resultQuery = $conn->prepare(" |
||
| 96 | SELECT 'id' AS source, user_id AS value FROM $userTable |
||
| 97 | WHERE user_name = :username |
||
| 98 | UNION |
||
| 99 | SELECT 'account-age' AS source, user_registration AS value FROM $userTable |
||
| 100 | WHERE user_name=:username |
||
| 101 | UNION |
||
| 102 | SELECT 'edit-count' AS source, user_editcount AS value FROM $userTable |
||
| 103 | WHERE user_name=:username |
||
| 104 | UNION |
||
| 105 | SELECT 'user-page' AS source, page_len AS value FROM $pageTable |
||
| 106 | WHERE page_namespace=2 AND page_title=:username |
||
| 107 | UNION |
||
| 108 | SELECT 'patrols' AS source, COUNT(*) AS value FROM $loggingTable |
||
| 109 | WHERE log_type='patrol' |
||
| 110 | AND log_action='patrol' |
||
| 111 | AND log_namespace=0 |
||
| 112 | AND log_deleted=0 AND log_user_text=:username |
||
| 113 | UNION |
||
| 114 | SELECT 'blocks' AS source, COUNT(*) AS value FROM $loggingTable l |
||
| 115 | INNER JOIN $userTable u ON l.log_user = u.user_id |
||
| 116 | WHERE l.log_type='block' AND l.log_action='block' |
||
| 117 | AND l.log_namespace=2 AND l.log_deleted=0 AND u.user_name=:username |
||
| 118 | UNION |
||
| 119 | SELECT 'afd' AS source, COUNT(*) AS value FROM $revisionTable |
||
| 120 | WHERE rev_page LIKE 'Articles for deletion/%' |
||
| 121 | AND rev_page NOT LIKE 'Articles_for_deletion/Log/%' |
||
| 122 | AND rev_user_text=:username |
||
| 123 | UNION |
||
| 124 | SELECT 'recent-activity' AS source, COUNT(*) AS value FROM $revisionTable |
||
| 125 | WHERE rev_user_text=:username AND rev_timestamp > (now()-INTERVAL 730 day) AND rev_timestamp < now() |
||
| 126 | UNION |
||
| 127 | SELECT 'aiv' AS source, COUNT(*) AS value FROM $revisionTable |
||
| 128 | WHERE rev_page LIKE 'Administrator intervention against vandalism%' AND rev_user_text=:username |
||
| 129 | UNION |
||
| 130 | SELECT 'edit-summaries' AS source, COUNT(*) AS value FROM $revisionTable JOIN page ON rev_page=page_id |
||
| 131 | WHERE page_namespace=0 AND rev_user_text=:username |
||
| 132 | UNION |
||
| 133 | SELECT 'namespaces' AS source, count(*) AS value FROM $revisionTable JOIN page ON rev_page=page_id |
||
| 134 | WHERE rev_user_text=:username AND page_namespace=0 |
||
| 135 | UNION |
||
| 136 | SELECT 'pages-created-live' AS source, COUNT(*) AS value FROM $revisionTable |
||
| 137 | WHERE rev_user_text=:username AND rev_parent_id=0 |
||
| 138 | UNION |
||
| 139 | SELECT 'pages-created-deleted' AS source, COUNT(*) AS value FROM $archiveTable |
||
| 140 | WHERE ar_user_text=:username AND ar_parent_id=0 |
||
| 141 | UNION |
||
| 142 | SELECT 'rpp' AS source, COUNT(*) AS value FROM $revisionTable |
||
| 143 | WHERE rev_page LIKE 'Requests_for_page_protection%' AND rev_user_text=:username |
||
| 144 | "); |
||
| 145 | |||
| 146 | $resultQuery->bindParam("username", $username); |
||
| 147 | $resultQuery->execute(); |
||
| 148 | |||
| 149 | // Fetch the result data |
||
| 150 | $results = $resultQuery->fetchAll(); |
||
| 151 | |||
| 152 | $master = []; |
||
| 153 | $total = 0; |
||
| 154 | |||
| 155 | $id = 0; |
||
| 156 | |||
| 157 | foreach ($results as $row) { |
||
| 158 | $key = $row["source"]; |
||
| 159 | $value = $row["value"]; |
||
| 160 | |||
| 161 | if ($key == "acct_age") { |
||
| 162 | $now = new DateTime(); |
||
| 163 | $date = new DateTime($value); |
||
| 164 | $diff = $date->diff($now); |
||
| 165 | $formula = 365*$diff->format("%y")+30*$diff->format("%m")+$diff->format("%d"); |
||
| 166 | $value = $formula-365; |
||
| 167 | } |
||
| 168 | |||
| 169 | if ($key == "id") { |
||
| 170 | $id = $value; |
||
| 171 | } else { |
||
| 172 | $multiplierKey = strtoupper($row["source"] . "_MULT"); |
||
| 173 | $multiplier = ( isset($$multiplierKey) ? $$multiplierKey : 1 ); |
||
| 174 | $score = max(min($value * $multiplier, 100), -100); |
||
| 175 | $master[$key]["mult"] = $multiplier; |
||
| 176 | $master[$key]["value"] = $value; |
||
| 177 | $master[$key]["score"] = $score; |
||
| 178 | $total += $score; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | View Code Duplication | if ($id == 0) { |
|
| 183 | $this->addFlash("notice", [ "no-result", $username ]); |
||
| 184 | return $this->redirectToRoute("AdminScore", [ "project"=>$project ]); |
||
| 185 | } |
||
| 186 | |||
| 187 | return $this->render('adminscore/result.html.twig', [ |
||
| 188 | 'xtPage' => 'adminscore', |
||
| 189 | 'xtTitle' => $username, |
||
| 190 | 'projectUrl' => $url, |
||
| 191 | 'username' => $username, |
||
| 192 | 'project' => $wikiName, |
||
| 193 | 'master' => $master, |
||
| 194 | 'total' => $total, |
||
| 195 | ]); |
||
| 196 | } |
||
| 197 | } |
||
| 198 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.