| Conditions | 1 |
| Paths | 1 |
| Total Lines | 106 |
| 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 |
||
| 52 | public function resultAction($project, $username) |
||
| 53 | { |
||
| 54 | /** @var LabsHelper $lh */ |
||
| 55 | $lh = $this->get('app.labs_helper'); |
||
| 56 | /** @var EditCounterHelper $ec */ |
||
| 57 | $ec = $this->get('app.editcounter_helper'); |
||
| 58 | /** @var ApiHelper $api */ |
||
| 59 | $api = $this->get('app.api_helper'); |
||
| 60 | /** @var AutomatedEditsHelper $automatedEditsHelper */ |
||
| 61 | $automatedEditsHelper = $this->get('app.automated_edits_helper'); |
||
| 62 | |||
| 63 | // Check, clean, and get inputs. |
||
| 64 | $lh->checkEnabled("ec"); |
||
| 65 | $username = ucfirst($username); |
||
| 66 | $dbValues = $lh->databasePrepare($project); |
||
| 67 | $dbName = $dbValues["dbName"]; |
||
| 68 | $wikiName = $dbValues["wikiName"]; |
||
| 69 | $url = $dbValues["url"]; |
||
| 70 | |||
| 71 | // Get statistics. |
||
| 72 | $userId = $ec->getUserId($username); |
||
| 73 | $revisionCounts = $ec->getRevisionCounts($userId); |
||
| 74 | $pageCounts = $ec->getPageCounts($username, $revisionCounts['total']); |
||
| 75 | $logCounts = $ec->getLogCounts($userId); |
||
| 76 | $namespaceTotals = $ec->getNamespaceTotals($userId); |
||
| 77 | $automatedEditsSummary = $automatedEditsHelper->getEditsSummary($userId); |
||
| 78 | $topProjectsEditCounts = $ec->getTopProjectsEditCounts($username); |
||
| 79 | $recentGlobalContribs = $ec->getRecentGlobalContribs($username); |
||
| 80 | $yearlyTotalsByNamespace = $ec->getYearlyTotalsByNamespace($username); |
||
| 81 | |||
| 82 | // Give it all to the template. |
||
| 83 | return $this->render('editCounter/result.html.twig', [ |
||
| 84 | 'xtTitle' => 'tool_ec', |
||
| 85 | 'xtPage' => 'ec', |
||
| 86 | 'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..'), |
||
| 87 | 'is_labs' => $lh->isLabs(), |
||
| 88 | |||
| 89 | // Project. |
||
| 90 | 'project' => $project, |
||
| 91 | 'wiki' => $dbName, |
||
| 92 | 'name' => $wikiName, |
||
| 93 | 'url' => $url, |
||
| 94 | 'namespaces' => $api->namespaces($project), |
||
| 95 | |||
| 96 | // User and groups. |
||
| 97 | 'username' => $username, |
||
| 98 | 'user_id' => $userId, |
||
| 99 | 'user_groups' => $api->groups($project, $username), |
||
| 100 | 'global_groups' => $api->globalGroups($project, $username), |
||
| 101 | |||
| 102 | // Revision counts. |
||
| 103 | 'deleted_edits' => $revisionCounts['deleted'], |
||
| 104 | 'total_edits' => $revisionCounts['total'], |
||
| 105 | 'live_edits' => $revisionCounts['live'], |
||
| 106 | 'first_rev' => $revisionCounts['first'], |
||
| 107 | 'latest_rev' => $revisionCounts['last'], |
||
| 108 | 'days' => $revisionCounts['days'], |
||
| 109 | 'avg_per_day' => $revisionCounts['avg_per_day'], |
||
| 110 | 'rev_24h' => $revisionCounts['24h'], |
||
| 111 | 'rev_7d' => $revisionCounts['7d'], |
||
| 112 | 'rev_30d' => $revisionCounts['30d'], |
||
| 113 | 'rev_365d' => $revisionCounts['365d'], |
||
| 114 | 'rev_small' => $revisionCounts['small'], |
||
| 115 | 'rev_large' => $revisionCounts['large'], |
||
| 116 | 'with_comments' => $revisionCounts['with_comments'], |
||
| 117 | 'without_comments' => $revisionCounts['live'] - $revisionCounts['with_comments'], |
||
| 118 | 'minor_edits' => $revisionCounts['minor_edits'], |
||
| 119 | 'nonminor_edits' => $revisionCounts['live'] - $revisionCounts['minor_edits'], |
||
| 120 | |||
| 121 | // Page counts. |
||
| 122 | 'uniquePages' => $pageCounts['unique'], |
||
| 123 | 'pagesCreated' => $pageCounts['created'], |
||
| 124 | 'pagesMoved' => $pageCounts['moved'], |
||
| 125 | 'editsPerPage' => $pageCounts['edits_per_page'], |
||
| 126 | |||
| 127 | // Log counts (keys are 'log name'-'action'). |
||
| 128 | 'pagesThanked' => $logCounts['thanks-thank'], |
||
| 129 | 'pagesApproved' => $logCounts['review-approve'], // Merged -a, -i, and -ia approvals. |
||
| 130 | 'pagesPatrolled' => $logCounts['patrol-patrol'], |
||
| 131 | 'usersBlocked' => $logCounts['block-block'], |
||
| 132 | 'usersUnblocked' => $logCounts['block-unblock'], |
||
| 133 | 'pagesProtected' => $logCounts['protect-protect'], |
||
| 134 | 'pagesUnprotected' => $logCounts['protect-unprotect'], |
||
| 135 | 'pagesDeleted' => $logCounts['delete-delete'], |
||
| 136 | 'pagesDeletedRevision' => $logCounts['delete-revision'], |
||
| 137 | 'pagesRestored' => $logCounts['delete-restore'], |
||
| 138 | 'pagesImported' => $logCounts['import-import'], |
||
| 139 | 'files_uploaded' => $logCounts['upload-upload'], |
||
| 140 | 'files_modified' => $logCounts['upload-overwrite'], |
||
| 141 | 'files_uploaded_commons' => $logCounts['files_uploaded_commons'], |
||
| 142 | |||
| 143 | // Namespace Totals |
||
| 144 | 'namespaceArray' => $namespaceTotals, |
||
| 145 | 'namespaceTotal' => array_sum($namespaceTotals), |
||
| 146 | 'yearcounts' => $yearlyTotalsByNamespace, |
||
| 147 | |||
| 148 | // Semi-automated edits. |
||
| 149 | 'auto_edits' => $automatedEditsSummary, |
||
| 150 | 'auto_edits_total' => array_sum($automatedEditsSummary), |
||
| 151 | |||
| 152 | // Other projects. |
||
| 153 | 'top_projects_edit_counts' => $topProjectsEditCounts, |
||
| 154 | 'recent_global_contribs' => $recentGlobalContribs, |
||
| 155 | |||
| 156 | ]); |
||
| 157 | } |
||
| 158 | |||
| 207 |