Completed
Push — master ( 1ced49...3e4594 )
by Sam
03:18
created
src/AppBundle/Controller/EditCounterController.php 2 patches
Unused Use Statements   -4 removed lines patch added patch discarded remove patch
@@ -2,13 +2,9 @@
 block discarded – undo
2 2
 
3 3
 namespace AppBundle\Controller;
4 4
 
5
-use AppBundle\Helper\ApiHelper;
6
-use AppBundle\Helper\AutomatedEditsHelper;
7
-use AppBundle\Helper\LabsHelper;
8 5
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9 6
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10 7
 use Symfony\Component\HttpFoundation\Request;
11
-use Symfony\Component\VarDumper\VarDumper;
12 8
 use Xtools\EditCounter;
13 9
 use Xtools\EditCounterRepository;
14 10
 use Xtools\Project;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,10 +65,10 @@
 block discarded – undo
65 65
         $username = $request->query->get('username');
66 66
 
67 67
         if (($project || $queryProject) && $username) {
68
-            $routeParams = [ 'project'=>($project ?: $queryProject), 'username' => $username ];
68
+            $routeParams = ['project'=>($project ?: $queryProject), 'username' => $username];
69 69
             return $this->redirectToRoute("EditCounterResult", $routeParams);
70 70
         } elseif (!$project && $queryProject) {
71
-            return $this->redirectToRoute("EditCounterProject", [ 'project'=>$queryProject ]);
71
+            return $this->redirectToRoute("EditCounterProject", ['project'=>$queryProject]);
72 72
         }
73 73
 
74 74
         $project = ProjectRepository::getProject($queryProject, $this->container);
Please login to merge, or discard this patch.
src/Xtools/EditCounterRepository.php 1 patch
Spacing   +38 added lines, -38 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.' . $project->getDatabaseName() . '.' . $user->getUsername();
19
+        $cacheKey = 'revisioncounts.'.$project->getDatabaseName().'.'.$user->getUsername();
20 20
         if ($this->cache->hasItem($cacheKey)) {
21 21
             return $this->cache->getItem($cacheKey)->get();
22 22
         }
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     public function getRevisionDates(Project $project, User $user)
78 78
     {
79 79
         // Set up cache.
80
-        $cacheKey = 'revisiondates.' . $project->getDatabaseName() . '.' . $user->getUsername();
80
+        $cacheKey = 'revisiondates.'.$project->getDatabaseName().'.'.$user->getUsername();
81 81
         if ($this->cache->hasItem($cacheKey)) {
82 82
             return $this->cache->getItem($cacheKey)->get();
83 83
         }
@@ -149,10 +149,10 @@  discard block
 block discarded – undo
149 149
         $results = $resultQuery->fetchAll();
150 150
 
151 151
         $pageCounts = array_combine(
152
-            array_map(function ($e) {
152
+            array_map(function($e) {
153 153
                 return $e['source'];
154 154
             }, $results),
155
-            array_map(function ($e) {
155
+            array_map(function($e) {
156 156
                 return $e['value'];
157 157
             }, $results)
158 158
         );
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 
184 184
         // Query.
185 185
         $sql = "SELECT CONCAT(log_type, '-', log_action) AS source, COUNT(log_id) AS value
186
-            FROM " . $this->getTableName($project->getDatabaseName(), 'logging') . "
186
+            FROM " . $this->getTableName($project->getDatabaseName(), 'logging')."
187 187
             WHERE log_user = :userId
188 188
             GROUP BY log_type, log_action";
189 189
         $resultQuery = $this->getProjectsConnection()->prepare($sql);
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
         $resultQuery->execute();
193 193
         $results = $resultQuery->fetchAll();
194 194
         $logCounts = array_combine(
195
-            array_map(function ($e) {
195
+            array_map(function($e) {
196 196
                 return $e['source'];
197 197
             }, $results),
198
-            array_map(function ($e) {
198
+            array_map(function($e) {
199 199
                 return $e['value'];
200 200
             }, $results)
201 201
         );
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
         $resultQuery->bindParam(":id", $userId);
342 342
         $resultQuery->execute();
343 343
         $results = $resultQuery->fetchAll();
344
-        $namespaceTotals = array_combine(array_map(function ($e) {
344
+        $namespaceTotals = array_combine(array_map(function($e) {
345 345
             return $e['page_namespace'];
346
-        }, $results), array_map(function ($e) {
346
+        }, $results), array_map(function($e) {
347 347
             return $e['total'];
348 348
         }, $results));
349 349
         return $namespaceTotals;
@@ -365,14 +365,14 @@  discard block
 block discarded – undo
365 365
                 $revisions = $this->cacheGet($cacheKey);
366 366
             } else {
367 367
                 $sql =
368
-                    "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, " .
369
-                    " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, " .
370
-                    " page_title, page_namespace " . " FROM " .
371
-                    $this->labsHelper->getTable('revision', $project['dbName']) . "    JOIN " .
372
-                    $this->labsHelper->getTable('page', $project['dbName']) .
373
-                    "    ON (rev_page = page_id)" .
374
-                    " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username" .
375
-                    " ORDER BY rev_timestamp DESC" . " LIMIT 10";
368
+                    "SELECT rev_id, rev_timestamp, UNIX_TIMESTAMP(rev_timestamp) AS unix_timestamp, ".
369
+                    " rev_minor_edit, rev_deleted, rev_len, rev_parent_id, rev_comment, ".
370
+                    " page_title, page_namespace "." FROM ".
371
+                    $this->labsHelper->getTable('revision', $project['dbName'])."    JOIN ".
372
+                    $this->labsHelper->getTable('page', $project['dbName']).
373
+                    "    ON (rev_page = page_id)".
374
+                    " WHERE rev_timestamp > NOW() - INTERVAL $days DAY AND rev_user_text LIKE :username".
375
+                    " ORDER BY rev_timestamp DESC"." LIMIT 10";
376 376
                 $resultQuery = $this->replicas->prepare($sql);
377 377
                 $resultQuery->bindParam(":username", $username);
378 378
                 $resultQuery->execute();
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
             if (count($revisions) === 0) {
383 383
                 continue;
384 384
             }
385
-            $revsWithProject = array_map(function (&$item) use ($project) {
385
+            $revsWithProject = array_map(function(&$item) use ($project) {
386 386
                 $item['project_name'] = $project['wikiName'];
387 387
                 $item['project_url'] = $project['url'];
388 388
                 $item['project_db_name'] = $project['dbName'];
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
             }, $revisions);
393 393
             $allRevisions = array_merge($allRevisions, $revsWithProject);
394 394
         }
395
-        usort($allRevisions, function ($a, $b) {
396
-            return $b['rev_timestamp'] - $a['rev_timestamp'];
395
+        usort($allRevisions, function($a, $b) {
396
+            return $b['rev_timestamp']-$a['rev_timestamp'];
397 397
         });
398 398
 
399 399
         return array_slice($allRevisions, 0, $topN);
@@ -412,12 +412,12 @@  discard block
 block discarded – undo
412 412
         }
413 413
 
414 414
         $sql =
415
-            "SELECT " . "     YEAR(rev_timestamp) AS `year`," .
416
-            "     MONTH(rev_timestamp) AS `month`," . "     page_namespace," .
417
-            "     COUNT(rev_id) AS `count` " . " FROM " . $this->labsHelper->getTable('revision') .
418
-            "    JOIN " . $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" .
419
-            " WHERE rev_user_text = :username" .
420
-            " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace " .
415
+            "SELECT "."     YEAR(rev_timestamp) AS `year`,".
416
+            "     MONTH(rev_timestamp) AS `month`,"."     page_namespace,".
417
+            "     COUNT(rev_id) AS `count` "." FROM ".$this->labsHelper->getTable('revision').
418
+            "    JOIN ".$this->labsHelper->getTable('page')." ON (rev_page = page_id)".
419
+            " WHERE rev_user_text = :username".
420
+            " GROUP BY YEAR(rev_timestamp), MONTH(rev_timestamp), page_namespace ".
421 421
             " ORDER BY rev_timestamp DESC";
422 422
         $resultQuery = $this->replicas->prepare($sql);
423 423
         $resultQuery->bindParam(":username", $username);
@@ -439,14 +439,14 @@  discard block
 block discarded – undo
439 439
             if (!isset($out['totals'][$ns])) {
440 440
                 $out['totals'][$ns] = [];
441 441
             }
442
-            $out['totals'][$ns][$total['year'] . $total['month']] = $total['count'];
442
+            $out['totals'][$ns][$total['year'].$total['month']] = $total['count'];
443 443
         }
444 444
         // Fill in the blanks (where no edits were made in a given month for a namespace).
445 445
         for ($y = $out['min_year']; $y <= $out['max_year']; $y++) {
446 446
             for ($m = 1; $m <= 12; $m++) {
447 447
                 foreach ($out['totals'] as $nsId => &$total) {
448
-                    if (!isset($total[$y . $m])) {
449
-                        $total[$y . $m] = 0;
448
+                    if (!isset($total[$y.$m])) {
449
+                        $total[$y.$m] = 0;
450 450
                     }
451 451
                 }
452 452
             }
@@ -469,12 +469,12 @@  discard block
 block discarded – undo
469 469
         }
470 470
 
471 471
         $sql =
472
-            "SELECT " . "     SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`," .
473
-            "     page_namespace," . "     COUNT(rev_id) AS `count` " . " FROM " .
474
-            $this->labsHelper->getTable('revision') . "    JOIN " .
475
-            $this->labsHelper->getTable('page') . " ON (rev_page = page_id)" .
476
-            " WHERE rev_user_text = :username" .
477
-            " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace " .
472
+            "SELECT "."     SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4) AS `year`,".
473
+            "     page_namespace,"."     COUNT(rev_id) AS `count` "." FROM ".
474
+            $this->labsHelper->getTable('revision')."    JOIN ".
475
+            $this->labsHelper->getTable('page')." ON (rev_page = page_id)".
476
+            " WHERE rev_user_text = :username".
477
+            " GROUP BY SUBSTR(CAST(rev_timestamp AS CHAR(4)), 1, 4), page_namespace ".
478 478
             " ORDER BY rev_timestamp DESC ";
479 479
         $resultQuery = $this->replicas->prepare($sql);
480 480
         $resultQuery->bindParam(":username", $username);
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
         $hourInterval = 2;
514 514
         $xCalc = "ROUND(HOUR(rev_timestamp)/$hourInterval)*$hourInterval";
515 515
         $sql =
516
-            "SELECT " . "     DAYOFWEEK(rev_timestamp) AS `y`, " . "     $xCalc AS `x`, " .
517
-            "     COUNT(rev_id) AS `r` " . " FROM " . $this->labsHelper->getTable('revision') .
518
-            " WHERE rev_user_text = :username" . " GROUP BY DAYOFWEEK(rev_timestamp), $xCalc " .
516
+            "SELECT "."     DAYOFWEEK(rev_timestamp) AS `y`, "."     $xCalc AS `x`, ".
517
+            "     COUNT(rev_id) AS `r` "." FROM ".$this->labsHelper->getTable('revision').
518
+            " WHERE rev_user_text = :username"." GROUP BY DAYOFWEEK(rev_timestamp), $xCalc ".
519 519
             " ";
520 520
         $resultQuery = $this->replicas->prepare($sql);
521 521
         $resultQuery->bindParam(":username", $username);
Please login to merge, or discard this patch.