| Conditions | 5 |
| Paths | 6 |
| Total Lines | 134 |
| Code Lines | 76 |
| 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 |
||
| 72 | public function resultAction(Request $request) |
||
| 73 | { |
||
| 74 | // Second parameter causes it return a Redirect to the index if the user has too many edits. |
||
| 75 | $ret = $this->validateProjectAndUser($request, 'adminscore'); |
||
| 76 | if ($ret instanceof RedirectResponse) { |
||
|
|
|||
| 77 | return $ret; |
||
| 78 | } else { |
||
| 79 | list($projectData, $user) = $ret; |
||
| 80 | } |
||
| 81 | |||
| 82 | $dbName = $projectData->getDatabaseName(); |
||
| 83 | $projectRepo = $projectData->getRepository(); |
||
| 84 | |||
| 85 | $userTable = $projectRepo->getTableName($dbName, 'user'); |
||
| 86 | $pageTable = $projectRepo->getTableName($dbName, 'page'); |
||
| 87 | $loggingTable = $projectRepo->getTableName($dbName, 'logging', 'userindex'); |
||
| 88 | $revisionTable = $projectRepo->getTableName($dbName, 'revision'); |
||
| 89 | $archiveTable = $projectRepo->getTableName($dbName, 'archive'); |
||
| 90 | |||
| 91 | // MULTIPLIERS (to review) |
||
| 92 | $multipliers = [ |
||
| 93 | 'account-age-mult' => 1.25, # 0 if = 365 jours |
||
| 94 | 'edit-count-mult' => 1.25, # 0 if = 10 000 |
||
| 95 | 'user-page-mult' => 0.1, # 0 if = |
||
| 96 | 'patrols-mult' => 1, # 0 if = |
||
| 97 | 'blocks-mult' => 1.4, # 0 if = 10 |
||
| 98 | 'afd-mult' => 1.15, |
||
| 99 | 'recent-activity-mult' => 0.9, # 0 if = |
||
| 100 | 'aiv-mult' => 1.15, |
||
| 101 | 'edit-summaries-mult' => 0.8, # 0 if = |
||
| 102 | 'namespaces-mult' => 1.0, # 0 if = |
||
| 103 | 'pages-created-live-mult' => 1.4, # 0 if = |
||
| 104 | 'pages-created-deleted-mult' => 1.4, # 0 if = |
||
| 105 | 'rpp-mult' => 1.15, # 0 if = |
||
| 106 | 'user-rights-mult' => 0.75, # 0 if = |
||
| 107 | ]; |
||
| 108 | |||
| 109 | // Grab the connection to the replica database (which is separate from the above) |
||
| 110 | $conn = $this->get('doctrine')->getManager("replicas")->getConnection(); |
||
| 111 | |||
| 112 | // Prepare the query and execute |
||
| 113 | $resultQuery = $conn->prepare(" |
||
| 114 | SELECT 'account-age' AS source, user_registration AS value FROM $userTable |
||
| 115 | WHERE user_name = :username |
||
| 116 | UNION |
||
| 117 | SELECT 'edit-count' AS source, user_editcount AS value FROM $userTable |
||
| 118 | WHERE user_name = :username |
||
| 119 | UNION |
||
| 120 | SELECT 'user-page' AS source, page_len AS value FROM $pageTable |
||
| 121 | WHERE page_namespace = 2 AND page_title = :username |
||
| 122 | UNION |
||
| 123 | SELECT 'patrols' AS source, COUNT(*) AS value FROM $loggingTable |
||
| 124 | WHERE log_type = 'patrol' |
||
| 125 | AND log_action = 'patrol' |
||
| 126 | AND log_namespace = 0 |
||
| 127 | AND log_deleted = 0 AND log_user_text = :username |
||
| 128 | UNION |
||
| 129 | SELECT 'blocks' AS source, COUNT(*) AS value FROM $loggingTable l |
||
| 130 | INNER JOIN $userTable u ON l.log_user = u.user_id |
||
| 131 | WHERE l.log_type = 'block' AND l.log_action = 'block' |
||
| 132 | AND l.log_namespace = 2 AND l.log_deleted = 0 AND u.user_name = :username |
||
| 133 | UNION |
||
| 134 | SELECT 'afd' AS source, COUNT(*) AS value FROM $revisionTable r |
||
| 135 | INNER JOIN $pageTable p on p.page_id = r.rev_page |
||
| 136 | WHERE p.page_title LIKE 'Articles_for_deletion/%' |
||
| 137 | AND p.page_title NOT LIKE 'Articles_for_deletion/Log/%' |
||
| 138 | AND r.rev_user_text = :username |
||
| 139 | UNION |
||
| 140 | SELECT 'recent-activity' AS source, COUNT(*) AS value FROM $revisionTable |
||
| 141 | WHERE rev_user_text = :username AND rev_timestamp > (now()-INTERVAL 730 day) AND rev_timestamp < now() |
||
| 142 | UNION |
||
| 143 | SELECT 'aiv' AS source, COUNT(*) AS value FROM $revisionTable r |
||
| 144 | INNER JOIN $pageTable p on p.page_id = r.rev_page |
||
| 145 | WHERE p.page_title LIKE 'Administrator_intervention_against_vandalism%' |
||
| 146 | AND r.rev_user_text = :username |
||
| 147 | UNION |
||
| 148 | SELECT 'edit-summaries' AS source, COUNT(*) AS value FROM $revisionTable JOIN $pageTable ON rev_page = page_id |
||
| 149 | WHERE page_namespace = 0 AND rev_user_text = :username |
||
| 150 | UNION |
||
| 151 | SELECT 'namespaces' AS source, count(*) AS value FROM $revisionTable JOIN $pageTable ON rev_page = page_id |
||
| 152 | WHERE rev_user_text = :username AND page_namespace = 0 |
||
| 153 | UNION |
||
| 154 | SELECT 'pages-created-live' AS source, COUNT(*) AS value FROM $revisionTable |
||
| 155 | WHERE rev_user_text = :username AND rev_parent_id = 0 |
||
| 156 | UNION |
||
| 157 | SELECT 'pages-created-deleted' AS source, COUNT(*) AS value FROM $archiveTable |
||
| 158 | WHERE ar_user_text = :username AND ar_parent_id = 0 |
||
| 159 | UNION |
||
| 160 | SELECT 'rpp' AS source, COUNT(*) AS value FROM $revisionTable r |
||
| 161 | INNER JOIN $pageTable p on p.page_id = r.rev_page |
||
| 162 | WHERE p.page_title LIKE 'Requests_for_page_protection%' |
||
| 163 | AND r.rev_user_text = :username; |
||
| 164 | "); |
||
| 165 | |||
| 166 | $username = $user->getUsername(); |
||
| 167 | $resultQuery->bindParam("username", $username); |
||
| 168 | $resultQuery->execute(); |
||
| 169 | |||
| 170 | // Fetch the result data |
||
| 171 | $results = $resultQuery->fetchAll(); |
||
| 172 | |||
| 173 | $master = []; |
||
| 174 | $total = 0; |
||
| 175 | |||
| 176 | foreach ($results as $row) { |
||
| 177 | $key = $row['source']; |
||
| 178 | $value = $row['value']; |
||
| 179 | |||
| 180 | if ($key === 'account-age') { |
||
| 181 | $now = new DateTime(); |
||
| 182 | $date = new DateTime($value); |
||
| 183 | $diff = $date->diff($now); |
||
| 184 | $formula = 365 * $diff->format('%y') + 30 * $diff->format('%m') + $diff->format('%d'); |
||
| 185 | $value = $formula - 365; |
||
| 186 | } |
||
| 187 | |||
| 188 | $multiplierKey = $row['source'] . '-mult'; |
||
| 189 | $multiplier = isset($multipliers[$multiplierKey]) ? $multipliers[$multiplierKey] : 1; |
||
| 190 | $score = max(min($value * $multiplier, 100), -100); |
||
| 191 | $master[$key]['mult'] = $multiplier; |
||
| 192 | $master[$key]['value'] = $value; |
||
| 193 | $master[$key]['score'] = $score; |
||
| 194 | $total += $score; |
||
| 195 | } |
||
| 196 | |||
| 197 | return $this->render('adminscore/result.html.twig', [ |
||
| 198 | 'xtPage' => 'adminscore', |
||
| 199 | 'xtTitle' => $username, |
||
| 200 | 'project' => $projectData, |
||
| 201 | 'user' => $user, |
||
| 202 | 'master' => $master, |
||
| 203 | 'total' => $total, |
||
| 204 | ]); |
||
| 205 | } |
||
| 206 | } |
||
| 207 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.