Completed
Push — master ( c9d0e3...458768 )
by Sam
08:17
created
src/AppBundle/Controller/EditCounterController.php 1 patch
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -3,16 +3,13 @@
 block discarded – undo
3 3
 namespace AppBundle\Controller;
4 4
 
5 5
 use AppBundle\Helper\ApiHelper;
6
-use AppBundle\Helper\AutomatedEditsHelper;
7 6
 use AppBundle\Helper\LabsHelper;
8 7
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9 8
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10 9
 use Symfony\Component\HttpFoundation\Request;
11 10
 use Xtools\EditCounter;
12 11
 use Xtools\EditCounterRepository;
13
-use Xtools\Project;
14 12
 use Xtools\ProjectRepository;
15
-use Xtools\User;
16 13
 use Xtools\UserRepository;
17 14
 
18 15
 class EditCounterController extends Controller
Please login to merge, or discard this patch.
src/Xtools/EditCounterRepository.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     public function getRevisionCounts(Project $project, User $user)
17 17
     {
18 18
         // Set up cache.
19
-        $cacheKey = 'revisioncounts.' . $user->getId($project);
19
+        $cacheKey = 'revisioncounts.'.$user->getId($project);
20 20
         if ($this->cache->hasItem($cacheKey)) {
21 21
             $msg = "Using logged revision counts";
22 22
             $this->log->debug($msg, [$project->getDatabaseName(), $user->getUsername()]);
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             $val = $resultQuery->fetchColumn();
59 59
             $revisionCounts[$varName] = $val ?: 0;
60 60
         }
61
-        $duration = microtime() - $start;
61
+        $duration = microtime()-$start;
62 62
         $this->log->debug(
63 63
             "Retrieved revision counts in $duration",
64 64
             [$project->getDatabaseName(), $user->getUsername()]
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
         $resultQuery->execute();
131 131
         $results = $resultQuery->fetchAll();
132 132
 
133
-        $pageCounts = array_combine(array_map(function ($e) {
133
+        $pageCounts = array_combine(array_map(function($e) {
134 134
             return $e['source'];
135
-        }, $results), array_map(function ($e) {
135
+        }, $results), array_map(function($e) {
136 136
             return $e['value'];
137 137
         }, $results));
138 138
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
     public function getLogCounts(Project $project, User $user)
149 149
     {
150 150
         $sql = "SELECT CONCAT(log_type, '-', log_action) AS source, COUNT(log_id) AS value
151
-            FROM " . $this->getTableName($project->getDatabaseName(), 'logging') . "
151
+            FROM " . $this->getTableName($project->getDatabaseName(), 'logging')."
152 152
             WHERE log_user = :userId
153 153
             GROUP BY log_type, log_action";
154 154
         $resultQuery = $this->getProjectsConnection()->prepare($sql);
@@ -157,10 +157,10 @@  discard block
 block discarded – undo
157 157
         $resultQuery->execute();
158 158
         $results = $resultQuery->fetchAll();
159 159
         $logCounts = array_combine(
160
-            array_map(function ($e) {
160
+            array_map(function($e) {
161 161
                 return $e['source'];
162 162
             }, $results),
163
-            array_map(function ($e) {
163
+            array_map(function($e) {
164 164
                 return $e['value'];
165 165
             }, $results)
166 166
         );
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
     public function getTopProjectsEditCounts($projectUrl, $username, $numProjects = 10)
243 243
     {
244 244
         $this->debug("Getting top project edit counts for $username");
245
-        $cacheKey = 'topprojectseditcounts.' . $username;
245
+        $cacheKey = 'topprojectseditcounts.'.$username;
246 246
         if ($this->cacheHas($cacheKey)) {
247 247
             return $this->cacheGet($cacheKey);
248 248
         }
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         if (false === $topEditCounts) {
255 255
             // If no CentralAuth, fall back to querying each database in turn.
256 256
             foreach ($this->labsHelper->getProjectsInfo() as $project) {
257
-                $this->container->get('logger')->debug('Getting edit count for ' . $project['url']);
257
+                $this->container->get('logger')->debug('Getting edit count for '.$project['url']);
258 258
                 $revisionTableName = $this->labsHelper->getTable('revision', $project['dbName']);
259 259
                 $sql = "SELECT COUNT(rev_id) FROM $revisionTableName WHERE rev_user_text=:username";
260 260
                 $stmt = $this->replicas->prepare($sql);
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
                 $topEditCounts[$project['dbName']] = array_merge($project, ['total' => $total]);
265 265
             }
266 266
         }
267
-        uasort($topEditCounts, function ($a, $b) {
268
-            return $b['total'] - $a['total'];
267
+        uasort($topEditCounts, function($a, $b) {
268
+            return $b['total']-$a['total'];
269 269
         });
270 270
         $out = array_slice($topEditCounts, 0, $numProjects);
271 271
 
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
     {
285 285
         $userId = $this->getUserId($username);
286 286
         $sql = "SELECT page_namespace, count(rev_id) AS total
287
-            FROM " . $this->labsHelper->getTable('revision') . " r
288
-                JOIN " . $this->labsHelper->getTable('page') . " p on r.rev_page = p.page_id
287
+            FROM " . $this->labsHelper->getTable('revision')." r
288
+                JOIN " . $this->labsHelper->getTable('page')." p on r.rev_page = p.page_id
289 289
             WHERE r.rev_user = :id GROUP BY page_namespace";
290 290
         $resultQuery = $this->replicas->prepare($sql);
291 291
         $resultQuery->bindParam(":id", $userId);
292 292
         $resultQuery->execute();
293 293
         $results = $resultQuery->fetchAll();
294
-        $namespaceTotals = array_combine(array_map(function ($e) {
294
+        $namespaceTotals = array_combine(array_map(function($e) {
295 295
             return $e['page_namespace'];
296
-        }, $results), array_map(function ($e) {
296
+        }, $results), array_map(function($e) {
297 297
             return $e['total'];
298 298
         }, $results));
299 299
 
@@ -316,14 +316,14 @@  discard block
 block discarded – undo
316 316
                 $revisions = $this->cacheGet($cacheKey);
317 317
             } else {
318 318
                 $sql =
319
-                    "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, " .
320
-                    " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, " .
321
-                    " page_title, page_namespace " . " FROM " .
322
-                    $this->labsHelper->getTable('revision', $project['dbName']) . "    JOIN " .
323
-                    $this->labsHelper->getTable('page', $project['dbName']) .
324
-                    "    ON (rev_page = page_id)" .
325
-                    " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username" .
326
-                    " ORDER BY rev_timestamp DESC" . " LIMIT 10";
319
+                    "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, ".
320
+                    " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, ".
321
+                    " page_title, page_namespace "." FROM ".
322
+                    $this->labsHelper->getTable('revision', $project['dbName'])."    JOIN ".
323
+                    $this->labsHelper->getTable('page', $project['dbName']).
324
+                    "    ON (rev_page = page_id)".
325
+                    " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username".
326
+                    " ORDER BY rev_timestamp DESC"." LIMIT 10";
327 327
                 $resultQuery = $this->replicas->prepare($sql);
328 328
                 $resultQuery->bindParam(":username", $username);
329 329
                 $resultQuery->execute();
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
             if (count($revisions) === 0) {
334 334
                 continue;
335 335
             }
336
-            $revsWithProject = array_map(function (&$item) use ($project) {
336
+            $revsWithProject = array_map(function(&$item) use ($project) {
337 337
                 $item['project_name'] = $project['wikiName'];
338 338
                 $item['project_url'] = $project['url'];
339 339
                 $item['project_db_name'] = $project['dbName'];
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
             }, $revisions);
344 344
             $allRevisions = array_merge($allRevisions, $revsWithProject);
345 345
         }
346
-        usort($allRevisions, function ($a, $b) {
347
-            return $b['rev_timestamp'] - $a['rev_timestamp'];
346
+        usort($allRevisions, function($a, $b) {
347
+            return $b['rev_timestamp']-$a['rev_timestamp'];
348 348
         });
349 349
 
350 350
         return array_slice($allRevisions, 0, $topN);
@@ -363,12 +363,12 @@  discard block
 block discarded – undo
363 363
         }
364 364
 
365 365
         $sql =
366
-            "SELECT " . "     YEAR(rev_timestamp) AS `year`," .
367
-            "     MONTH(rev_timestamp) AS `month`," . "     page_namespace," .
368
-            "     COUNT(rev_id) AS `count` " . " FROM " . $this->labsHelper->getTable('revision') .
369
-            "    JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" .
370
-            " WHERE rev_user_text = :username" .
371
-            " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " .
366
+            "SELECT "."     YEAR(rev_timestamp) AS `year`,".
367
+            "     MONTH(rev_timestamp) AS `month`,"."     page_namespace,".
368
+            "     COUNT(rev_id) AS `count` "." FROM ".$this->labsHelper->getTable('revision').
369
+            "    JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)".
370
+            " WHERE rev_user_text = :username".
371
+            " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace ".
372 372
             " ORDER BY rev_timestamp DESC";
373 373
         $resultQuery = $this->replicas->prepare($sql);
374 374
         $resultQuery->bindParam(":username", $username);
@@ -390,14 +390,14 @@  discard block
 block discarded – undo
390 390
             if (!isset($out['totals'][$ns])) {
391 391
                 $out['totals'][$ns] = [];
392 392
             }
393
-            $out['totals'][$ns][$total['year'] . $total['month']] = $total['count'];
393
+            $out['totals'][$ns][$total['year'].$total['month']] = $total['count'];
394 394
         }
395 395
         // Fill in the blanks (where no edits were made in a given month for a namespace).
396 396
         for ($y = $out['min_year']; $y <= $out['max_year']; $y++) {
397 397
             for ($m = 1; $m <= 12; $m++) {
398 398
                 foreach ($out['totals'] as $nsId => &$total) {
399
-                    if (!isset($total[$y . $m])) {
400
-                        $total[$y . $m] = 0;
399
+                    if (!isset($total[$y.$m])) {
400
+                        $total[$y.$m] = 0;
401 401
                     }
402 402
                 }
403 403
             }
@@ -420,12 +420,12 @@  discard block
 block discarded – undo
420 420
         }
421 421
 
422 422
         $sql =
423
-            "SELECT " . "     SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`," .
424
-            "     page_namespace," . "     COUNT(rev_id) AS `count` " . " FROM " .
425
-            $this->labsHelper->getTable('revision') . "    JOIN " .
426
-            $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" .
427
-            " WHERE rev_user_text = :username" .
428
-            " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace " .
423
+            "SELECT "."     SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`,".
424
+            "     page_namespace,"."     COUNT(rev_id) AS `count` "." FROM ".
425
+            $this->labsHelper->getTable('revision')."    JOIN ".
426
+            $this->labsHelper->getTable('page')." ON (rev_page = page_id)".
427
+            " WHERE rev_user_text = :username".
428
+            " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace ".
429 429
             " ORDER BY rev_timestamp DESC ";
430 430
         $resultQuery = $this->replicas->prepare($sql);
431 431
         $resultQuery->bindParam(":username", $username);
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
         $hourInterval = 2;
465 465
         $xCalc = "ROUND(HOUR(rev_timestamp)/$hourInterval)*$hourInterval";
466 466
         $sql =
467
-            "SELECT " . "     DAYOFWEEK(rev_timestamp) AS `y`, " . "     $xCalc AS `x`, " .
468
-            "     COUNT(rev_id) AS `r` " . " FROM " . $this->labsHelper->getTable('revision') .
469
-            " WHERE rev_user_text = :username" . " GROUP BY DAYOFWEEK(rev_timestamp), $xCalc " .
467
+            "SELECT "."     DAYOFWEEK(rev_timestamp) AS `y`, "."     $xCalc AS `x`, ".
468
+            "     COUNT(rev_id) AS `r` "." FROM ".$this->labsHelper->getTable('revision').
469
+            " WHERE rev_user_text = :username"." GROUP BY DAYOFWEEK(rev_timestamp), $xCalc ".
470 470
             " ";
471 471
         $resultQuery = $this->replicas->prepare($sql);
472 472
         $resultQuery->bindParam(":username", $username);
Please login to merge, or discard this patch.
src/Xtools/EditCounter.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      */
41 41
     protected function getRevisionCounts()
42 42
     {
43
-        if (! is_array($this->revisionCounts)) {
43
+        if (!is_array($this->revisionCounts)) {
44 44
             $this->revisionCounts = $this->getRepository()
45 45
                 ->getRevisionCounts($this->project, $this->user);
46 46
         }
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      */
54 54
     protected function getRevisionDates()
55 55
     {
56
-        if (! is_array($this->revisionDates)) {
56
+        if (!is_array($this->revisionDates)) {
57 57
             $this->revisionDates = $this->getRepository()
58 58
                 ->getRevisionDates($this->project, $this->user);
59 59
         }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     protected function getPageCounts()
68 68
     {
69
-        if (! is_array($this->pageCounts)) {
69
+        if (!is_array($this->pageCounts)) {
70 70
             $this->pageCounts = $this->getRepository()
71 71
                 ->getPageCounts($this->project, $this->user);
72 72
         }
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     protected function getLogCounts()
81 81
     {
82
-        if (! is_array($this->logCounts)) {
82
+        if (!is_array($this->logCounts)) {
83 83
             $this->logCounts = $this->getRepository()
84 84
                 ->getLogCounts($this->project, $this->user);
85 85
         }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     public function countAllRevisions()
110 110
     {
111
-        return $this->countLiveRevisions() + $this->countDeletedRevisions();
111
+        return $this->countLiveRevisions()+$this->countDeletedRevisions();
112 112
     }
113 113
 
114 114
     /**
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function countRevisionsWithoutComments()
129 129
     {
130
-        return $this->countAllRevisions() - $this->countRevisionsWithComments();
130
+        return $this->countAllRevisions()-$this->countRevisionsWithComments();
131 131
     }
132 132
 
133 133
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function countAllPagesEdited()
182 182
     {
183
-        return $this->countLivePagesEdited() + $this->countDeletedPagesEdited();
183
+        return $this->countLivePagesEdited()+$this->countDeletedPagesEdited();
184 184
     }
185 185
 
186 186
     /**
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      */
199 199
     public function countPagesCreated()
200 200
     {
201
-        return $this->countCreatedPagesLive() + $this->countPagesCreatedDeleted();
201
+        return $this->countCreatedPagesLive()+$this->countPagesCreatedDeleted();
202 202
     }
203 203
 
204 204
     /**
@@ -328,9 +328,9 @@  discard block
 block discarded – undo
328 328
     public function approvals()
329 329
     {
330 330
         $logCounts = $this->getLogCounts();
331
-        $total = $logCounts['review-approve'] +
332
-        (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0) +
333
-        (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0) +
331
+        $total = $logCounts['review-approve']+
332
+        (!empty($logCounts['review-approve-a']) ? $logCounts['review-approve-a'] : 0)+
333
+        (!empty($logCounts['review-approve-i']) ? $logCounts['review-approve-i'] : 0)+
334 334
         (!empty($logCounts['review-approve-ia']) ? $logCounts['review-approve-ia'] : 0);
335 335
         return $total;
336 336
     }
Please login to merge, or discard this patch.