Completed
Pull Request — master (#64)
by Sam
02:58
created
src/AppBundle/Controller/EditSummaryController.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,6 @@
 block discarded – undo
10 10
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
11 11
 use Symfony\Component\HttpFoundation\Request;
12 12
 use Symfony\Component\HttpFoundation\Response;
13
-use Psr\Cache\CacheItemPoolInterface;
14 13
 use Xtools\Project;
15 14
 use Xtools\ProjectRepository;
16 15
 use Xtools\User;
Please login to merge, or discard this patch.
Spacing   +4 added lines, -6 removed lines patch added patch discarded remove patch
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
     {
144 144
         $dbName = $project->getDatabaseName();
145 145
 
146
-        $cacheKey = 'editsummaryusage.' . $dbName . '.'
147
-            . $user->getCacheKey() . '.' . $namespace;
146
+        $cacheKey = 'editsummaryusage.'.$dbName.'.'
147
+            . $user->getCacheKey().'.'.$namespace;
148 148
 
149 149
         $cache = $this->container->get('cache.app');
150 150
         if ($cache->hasItem($cacheKey)) {
@@ -231,8 +231,7 @@  discard block
 block discarded – undo
231 231
             if ($row['rev_minor_edit'] == 0) {
232 232
                 if ($row['rev_comment'] !== '') {
233 233
                     isset($monthEditsummaryTotals[$monthkey]) ?
234
-                        $monthEditsummaryTotals[$monthkey]++ :
235
-                        $monthEditsummaryTotals[$monthkey] = 1;
234
+                        $monthEditsummaryTotals[$monthkey]++ : $monthEditsummaryTotals[$monthkey] = 1;
236 235
                     $totalSummariesMajor++;
237 236
                 }
238 237
 
@@ -249,8 +248,7 @@  discard block
 block discarded – undo
249 248
                 // If there is a comment, count it
250 249
                 if ($row['rev_comment'] !== '') {
251 250
                     isset($monthEditsummaryTotals[$monthkey]) ?
252
-                        $monthEditsummaryTotals[$monthkey]++ :
253
-                        $monthEditsummaryTotals[$monthkey] = 1;
251
+                        $monthEditsummaryTotals[$monthkey]++ : $monthEditsummaryTotals[$monthkey] = 1;
254 252
                     $totalSummariesMinor++;
255 253
                     $totalEditsMinor++;
256 254
                 } else {
Please login to merge, or discard this patch.
src/Xtools/UserRepository.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -695,7 +695,7 @@
 block discarded – undo
695 695
      * Get the combined regex and tags for all semi-automated tools,
696 696
      *   ready to be used in a query.
697 697
      * @param string $projectDomain Such as en.wikipedia.org
698
-     * @param $conn Doctrine\DBAL\Connection Used for proper escaping
698
+     * @param \Doctrine\DBAL\Connection $conn Doctrine\DBAL\Connection Used for proper escaping
699 699
      * @return string[] In the format:
700 700
      *    ['combined|regex', 'combined,tags']
701 701
      */
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
         $this->stopwatch->start($cacheKey, 'XTools');
80 80
         $api = $this->getMediawikiApi($project);
81
-        $params = [ "list"=>"users", "ususers"=>$username, "usprop"=>"groups" ];
81
+        $params = ["list"=>"users", "ususers"=>$username, "usprop"=>"groups"];
82 82
         $query = new SimpleRequest('query', $params);
83 83
         $result = [];
84 84
         $res = $api->getRequest($query);
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
         // Create the API query.
115 115
         $api = $this->getMediawikiApi($project);
116
-        $params = [ "meta"=>"globaluserinfo", "guiuser"=>$username, "guiprop"=>"groups" ];
116
+        $params = ["meta"=>"globaluserinfo", "guiuser"=>$username, "guiprop"=>"groups"];
117 117
         $query = new SimpleRequest('query', $params);
118 118
 
119 119
         // Get the result.
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
     {
158 158
         $username = $user->getUsername();
159 159
 
160
-        $cacheKey = 'pages.' . $project->getDatabaseName() . '.'
161
-            . $user->getCacheKey() . '.' . $namespace . '.' . $redirects;
160
+        $cacheKey = 'pages.'.$project->getDatabaseName().'.'
161
+            . $user->getCacheKey().'.'.$namespace.'.'.$redirects;
162 162
         if ($this->cache->hasItem($cacheKey)) {
163 163
             return $this->cache->getItem($cacheKey)->get();
164 164
         }
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
             JOIN $revisionTable ON page_id = rev_page
217 217
             $paJoin
218 218
             WHERE $whereRev AND rev_parent_id = '0' $namespaceConditionRev $redirectCondition
219
-            " . ($hasPageAssessments ? 'GROUP BY rev_page' : '') . "
219
+            ".($hasPageAssessments ? 'GROUP BY rev_page' : '')."
220 220
             )
221 221
 
222 222
             UNION
@@ -263,21 +263,21 @@  discard block
 block discarded – undo
263 263
      */
264 264
     public function countEdits(Project $project, User $user, $namespace = 'all', $start = '', $end = '')
265 265
     {
266
-        $cacheKey = 'editcount.' . $project->getDatabaseName() . '.'
267
-            . $user->getCacheKey() . '.' . $namespace;
266
+        $cacheKey = 'editcount.'.$project->getDatabaseName().'.'
267
+            . $user->getCacheKey().'.'.$namespace;
268 268
 
269 269
         $condBegin = '';
270 270
         $condEnd = '';
271 271
 
272 272
         if (!empty($start)) {
273
-            $cacheKey .= '.' . $start;
273
+            $cacheKey .= '.'.$start;
274 274
 
275 275
             // For the query
276 276
             $start = date('Ymd000000', strtotime($start));
277 277
             $condBegin = 'AND rev_timestamp >= :start ';
278 278
         }
279 279
         if (!empty($end)) {
280
-            $cacheKey .= '.' . $end;
280
+            $cacheKey .= '.'.$end;
281 281
 
282 282
             // For the query
283 283
             $end = date('Ymd235959', strtotime($end));
@@ -337,21 +337,21 @@  discard block
 block discarded – undo
337 337
      */
338 338
     public function countAutomatedEdits(Project $project, User $user, $namespace = 'all', $start = '', $end = '')
339 339
     {
340
-        $cacheKey = 'autoeditcount.' . $project->getDatabaseName() . '.'
341
-            . $user->getCacheKey() . '.' . $namespace;
340
+        $cacheKey = 'autoeditcount.'.$project->getDatabaseName().'.'
341
+            . $user->getCacheKey().'.'.$namespace;
342 342
 
343 343
         $condBegin = '';
344 344
         $condEnd = '';
345 345
 
346 346
         if (!empty($start)) {
347
-            $cacheKey .= '.' . $start;
347
+            $cacheKey .= '.'.$start;
348 348
 
349 349
             // For the query
350 350
             $start = date('Ymd000000', strtotime($start));
351 351
             $condBegin = 'AND rev_timestamp >= :start ';
352 352
         }
353 353
         if (!empty($end)) {
354
-            $cacheKey .= '.' . $end;
354
+            $cacheKey .= '.'.$end;
355 355
 
356 356
             // For the query
357 357
             $end = date('Ymd235959', strtotime($end));
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
             $tagJoin = $tags != '' ? "LEFT OUTER JOIN $tagTable ON ct_rev_id = rev_id" : '';
383 383
             $condTools[] = "ct_tag IN ($tags)";
384 384
         }
385
-        $condTool = 'AND (' . implode(' OR ', $condTools) . ')';
385
+        $condTool = 'AND ('.implode(' OR ', $condTools).')';
386 386
 
387 387
         $sql = "SELECT COUNT(DISTINCT(rev_id))
388 388
                 FROM $revisionTable
@@ -439,21 +439,21 @@  discard block
 block discarded – undo
439 439
         $end = '',
440 440
         $offset = 0
441 441
     ) {
442
-        $cacheKey = 'nonautoedits.' . $project->getDatabaseName() . '.'
443
-            . $user->getCacheKey() . '.' . $namespace . '.' . $offset;
442
+        $cacheKey = 'nonautoedits.'.$project->getDatabaseName().'.'
443
+            . $user->getCacheKey().'.'.$namespace.'.'.$offset;
444 444
 
445 445
         $condBegin = '';
446 446
         $condEnd = '';
447 447
 
448 448
         if (!empty($start)) {
449
-            $cacheKey .= '.' . $start;
449
+            $cacheKey .= '.'.$start;
450 450
 
451 451
             // For the query
452 452
             $start = date('Ymd000000', strtotime($start));
453 453
             $condBegin = 'AND revs.rev_timestamp >= :start ';
454 454
         }
455 455
         if (!empty($end)) {
456
-            $cacheKey .= '.' . $end;
456
+            $cacheKey .= '.'.$end;
457 457
 
458 458
             // For the query
459 459
             $end = date('Ymd235959', strtotime($end));
@@ -546,21 +546,21 @@  discard block
 block discarded – undo
546 546
         $start = '',
547 547
         $end = ''
548 548
     ) {
549
-        $cacheKey = 'autotoolcounts.' . $project->getDatabaseName() . '.'
550
-            . $user->getCacheKey() . '.' . $namespace;
549
+        $cacheKey = 'autotoolcounts.'.$project->getDatabaseName().'.'
550
+            . $user->getCacheKey().'.'.$namespace;
551 551
 
552 552
         $condBegin = '';
553 553
         $condEnd = '';
554 554
 
555 555
         if (!empty($start)) {
556
-            $cacheKey .= '.' . $start;
556
+            $cacheKey .= '.'.$start;
557 557
 
558 558
             // For the query
559 559
             $start = date('Ymd000000', strtotime($start));
560 560
             $condBegin = 'AND rev_timestamp >= :start ';
561 561
         }
562 562
         if (!empty($end)) {
563
-            $cacheKey .= '.' . $end;
563
+            $cacheKey .= '.'.$end;
564 564
 
565 565
             // For the query
566 566
             $end = date('Ymd235959', strtotime($end));
@@ -608,13 +608,13 @@  discard block
 block discarded – undo
608 608
                 if ($condTool === '') {
609 609
                     $condTool = "ct_tag = $tag";
610 610
                 } else {
611
-                    $condTool = '(' . $condTool . " OR ct_tag = $tag)";
611
+                    $condTool = '('.$condTool." OR ct_tag = $tag)";
612 612
                 }
613 613
             }
614 614
 
615 615
             // Developer error, no regex or tag provided for this tool.
616 616
             if ($condTool === '') {
617
-                throw new Exception("No regex or tag found for the tool $toolname. " .
617
+                throw new Exception("No regex or tag found for the tool $toolname. ".
618 618
                     "Please verify this entry in semi_automated.yml");
619 619
             }
620 620
 
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
         }
667 667
 
668 668
         // Sort the array by count
669
-        uasort($results, function ($a, $b) {
670
-            return $b['count'] - $a['count'];
669
+        uasort($results, function($a, $b) {
670
+            return $b['count']-$a['count'];
671 671
         });
672 672
 
673 673
         // Cache for 10 minutes, and return.
Please login to merge, or discard this patch.
tests/Xtools/EditTest.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,6 @@
 block discarded – undo
11 11
 use Xtools\Project;
12 12
 use Xtools\ProjectRepository;
13 13
 use Symfony\Component\DependencyInjection\Container;
14
-use AppBundle\Helper\AutomatedEditsHelper;
15 14
 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
16 15
 
17 16
 /**
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
         ]);
90 90
 
91 91
         $this->assertEquals(
92
-            "<script>alert("XSS baby")</script> " .
92
+            "<script>alert("XSS baby")</script> ".
93 93
                 "<a target='_blank' href='https://test.example.org/wiki/Test_page'>test page</a>",
94 94
             $edit->getWikifiedSummary()
95 95
         );
Please login to merge, or discard this patch.
src/AppBundle/Helper/AutomatedEditsHelper.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function isAutomated($summary, $projectDomain)
59 59
     {
60
-        return (bool) $this->getTool($summary, $projectDomain);
60
+        return (bool)$this->getTool($summary, $projectDomain);
61 61
     }
62 62
 
63 63
     /**
@@ -109,14 +109,14 @@  discard block
 block discarded – undo
109 109
 
110 110
         $revertEntries = array_filter(
111 111
             $this->getTools($projectDomain),
112
-            function ($tool) {
112
+            function($tool) {
113 113
                 return isset($tool['revert']);
114 114
             }
115 115
         );
116 116
 
117 117
         // If 'revert' is set to `true`, the use 'regex' as the regular expression,
118 118
         //  otherwise 'revert' is assumed to be the regex string.
119
-        $this->revertTools[$projectDomain] = array_map(function ($revertTool) {
119
+        $this->revertTools[$projectDomain] = array_map(function($revertTool) {
120 120
             return [
121 121
                 'link' => $revertTool['link'],
122 122
                 'regex' => $revertTool['revert'] === true ? $revertTool['regex'] : $revertTool['revert']
Please login to merge, or discard this patch.
src/Xtools/Edit.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         $this->page = $page;
50 50
 
51 51
         // Copy over supported attributes
52
-        $this->id = (int) $attrs['id'];
52
+        $this->id = (int)$attrs['id'];
53 53
 
54 54
         // Allow DateTime or string (latter assumed to be of format YmdHis)
55 55
         if ($attrs['timestamp'] instanceof DateTime) {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
         $isSection = preg_match_all("/^\/\* (.*?) \*\//", $summary, $sectionMatch);
199 199
 
200 200
         if ($isSection) {
201
-            $pageUrl = $this->getProject()->getUrl(false) . str_replace(
201
+            $pageUrl = $this->getProject()->getUrl(false).str_replace(
202 202
                 '$1',
203 203
                 $this->getPage()->getTitle(),
204 204
                 $this->getProject()->getArticlePath()
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
             // Must have underscores for the link to properly go to the section
209 209
             $sectionTitleLink = htmlspecialchars(str_replace(' ', '_', $sectionTitle));
210 210
 
211
-            $sectionWikitext = "<a target='_blank' href='$pageUrl#$sectionTitleLink'>&rarr;</a>" .
212
-                "<em class='text-muted'>" . htmlspecialchars($sectionTitle) . ":</em> ";
211
+            $sectionWikitext = "<a target='_blank' href='$pageUrl#$sectionTitleLink'>&rarr;</a>".
212
+                "<em class='text-muted'>".htmlspecialchars($sectionTitle).":</em> ";
213 213
             $summary = str_replace($sectionMatch[0][0], $sectionWikitext, $summary);
214 214
         }
215 215
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
             );
224 224
 
225 225
             // Use normalized page title (underscored, capitalized)
226
-            $pageUrl = $this->getProject()->getUrl(false) . str_replace(
226
+            $pageUrl = $this->getProject()->getUrl(false).str_replace(
227 227
                 '$1',
228 228
                 ucfirst(str_replace(' ', '_', $wikiLinkPath)),
229 229
                 $this->getProject()->getArticlePath()
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
     public function getDiffUrl()
262 262
     {
263 263
         $project = $this->getProject();
264
-        $path = str_replace('$1', 'Special:Diff/' . $this->id, $project->getArticlePath());
265
-        return rtrim($project->getUrl(), '/') . $path;
264
+        $path = str_replace('$1', 'Special:Diff/'.$this->id, $project->getArticlePath());
265
+        return rtrim($project->getUrl(), '/').$path;
266 266
     }
267 267
 
268 268
     /**
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
     public function getPermaUrl()
273 273
     {
274 274
         $project = $this->getProject();
275
-        $path = str_replace('$1', 'Special:PermaLink/' . $this->id, $project->getArticlePath());
276
-        return rtrim($project->getUrl(), '/') . $path;
275
+        $path = str_replace('$1', 'Special:PermaLink/'.$this->id, $project->getArticlePath());
276
+        return rtrim($project->getUrl(), '/').$path;
277 277
     }
278 278
 
279 279
     /**
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
      */
306 306
     public function isAutomated(Container $container)
307 307
     {
308
-        return (bool) $this->getTool($container);
308
+        return (bool)$this->getTool($container);
309 309
     }
310 310
 
311 311
     /**
Please login to merge, or discard this patch.
src/AppBundle/EventSubscriber/RateLimitSubscriber.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
      */
57 57
     public function onKernelController(FilterControllerEvent $event)
58 58
     {
59
-        $this->rateLimit = (int) $this->container->getParameter('app.rate_limit_count');
60
-        $this->rateDuration = (int) $this->container->getParameter('app.rate_limit_time');
59
+        $this->rateLimit = (int)$this->container->getParameter('app.rate_limit_count');
60
+        $this->rateDuration = (int)$this->container->getParameter('app.rate_limit_time');
61 61
 
62 62
         // Zero values indicate the rate limiting feature should be disabled.
63 63
         if ($this->rateLimit === 0 || $this->rateDuration === 0) {
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         }
66 66
 
67 67
         $controller = $event->getController();
68
-        $loggedIn = (bool) $this->container->get('session')->get('logged_in_user');
68
+        $loggedIn = (bool)$this->container->get('session')->get('logged_in_user');
69 69
 
70 70
         // No rate limits on index pages or if they are logged in.
71 71
         if ($controller[1] === 'indexAction' || $loggedIn) {
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
         $cacheItem = $cache->getItem($cacheKey);
86 86
 
87 87
         // If increment value already in cache, or start with 1.
88
-        $count = $cacheItem->isHit() ? (int) $cacheItem->get() + 1 : 1;
88
+        $count = $cacheItem->isHit() ? (int)$cacheItem->get()+1 : 1;
89 89
 
90 90
         // Check if limit has been exceeded, and if so, throw an error.
91 91
         if ($count > $this->rateLimit) {
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
         // Log the denied request
138 138
         $logger = $this->container->get('monolog.logger.rate_limit');
139 139
         $logger->info(
140
-            "<URI>: " . $request->getRequestUri() .
141
-            ($logComment != '' ? "\t<Reason>: $logComment" : '') .
142
-            "\t<User agent>: " . $request->headers->get('User-Agent')
140
+            "<URI>: ".$request->getRequestUri().
141
+            ($logComment != '' ? "\t<Reason>: $logComment" : '').
142
+            "\t<User agent>: ".$request->headers->get('User-Agent')
143 143
         );
144 144
 
145
-        throw new AccessDeniedHttpException("Possible spider crawl detected. " .
146
-            'If you are human, you are making too many requests during a short period of time. ' .
147
-            "Please wait $this->rateDuration minutes before reloading this tool. You can then " .
145
+        throw new AccessDeniedHttpException("Possible spider crawl detected. ".
146
+            'If you are human, you are making too many requests during a short period of time. '.
147
+            "Please wait $this->rateDuration minutes before reloading this tool. You can then ".
148 148
             'login to prevent this from happening again.');
149 149
     }
150 150
 }
Please login to merge, or discard this patch.