Completed
Pull Request — master (#114)
by MusikAnimal
02:18
created
src/AppBundle/Controller/ApiController.php 2 patches
Unused Use Statements   -6 removed lines patch added patch discarded remove patch
@@ -5,21 +5,15 @@
 block discarded – undo
5 5
 
6 6
 namespace AppBundle\Controller;
7 7
 
8
-use Exception;
9
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
10 8
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
11 9
 use Symfony\Component\HttpFoundation\Request;
12 10
 use Symfony\Component\HttpFoundation\Response;
13
-use Symfony\Component\Debug\Exception\FatalErrorException;
14 11
 use FOS\RestBundle\Controller\Annotations as Rest;
15 12
 use FOS\RestBundle\Controller\FOSRestController;
16 13
 use FOS\RestBundle\View\View;
17 14
 use Xtools\ProjectRepository;
18 15
 use Xtools\UserRepository;
19
-use Xtools\Page;
20
-use Xtools\PagesRepository;
21 16
 use Xtools\Edit;
22
-use DateTime;
23 17
 
24 18
 /**
25 19
  * Serves the external API of XTools.
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             $res['automated_editcount'] = $user->countAutomatedEdits($project, $namespace, $start, $end);
132 132
         }
133 133
 
134
-        $res['nonautomated_editcount'] = $res['total_editcount'] - $res['automated_editcount'];
134
+        $res['nonautomated_editcount'] = $res['total_editcount']-$res['automated_editcount'];
135 135
 
136 136
         $view = View::create()->setStatusCode(Response::HTTP_OK);
137 137
         $view->setData($res);
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
             if ($request->query->get('format') !== 'html') {
177 177
                 return new View(
178 178
                     [
179
-                        'error' => 'Unable to show any data. User has made over ' .
180
-                            $user->maxEdits() . ' edits.',
179
+                        'error' => 'Unable to show any data. User has made over '.
180
+                            $user->maxEdits().' edits.',
181 181
                     ],
182 182
                     Response::HTTP_FORBIDDEN
183 183
                 );
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
         if ($request->query->get('format') === 'html') {
194 194
             if ($edits) {
195
-                $edits = array_map(function ($attrs) use ($project, $username) {
195
+                $edits = array_map(function($attrs) use ($project, $username) {
196 196
                     $page = $project->getRepository()
197 197
                         ->getPage($project, $attrs['full_page_title']);
198 198
                     $pageTitles[] = $attrs['full_page_title'];
Please login to merge, or discard this patch.
src/AppBundle/Controller/ArticleInfoController.php 3 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
             $rendered = str_replace('"', '\"', trim($rendered));
86 86
 
87 87
             // Uglify temporary file.
88
-            $tmpFile = sys_get_temp_dir() . '/xtools_articleinfo_gadget.js';
88
+            $tmpFile = sys_get_temp_dir().'/xtools_articleinfo_gadget.js';
89 89
             $script = "echo \"$rendered\" | tee $tmpFile >/dev/null && ";
90
-            $script .= $this->get('kernel')->getRootDir() .
91
-                "/Resources/node_modules/uglify-es/bin/uglifyjs $tmpFile --mangle " .
90
+            $script .= $this->get('kernel')->getRootDir().
91
+                "/Resources/node_modules/uglify-es/bin/uglifyjs $tmpFile --mangle ".
92 92
                 "&& rm $tmpFile >/dev/null";
93 93
             $process = new Process($script);
94 94
             $process->run();
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
             $rendered = str_replace('\"', '"', trim($rendered));
108 108
 
109 109
             // Add comment after uglifying since it removes comments.
110
-            $rendered = "/**\n * This code was automatically generated and should not " .
111
-                "be manually edited.\n * For updates, please copy and paste from " .
112
-                $this->generateUrl('ArticleInfoGadget', ['uglify' => 1], UrlGeneratorInterface::ABSOLUTE_URL) .
113
-                "\n * Released under GPL v3 license.\n */\n" . $rendered;
110
+            $rendered = "/**\n * This code was automatically generated and should not ".
111
+                "be manually edited.\n * For updates, please copy and paste from ".
112
+                $this->generateUrl('ArticleInfoGadget', ['uglify' => 1], UrlGeneratorInterface::ABSOLUTE_URL).
113
+                "\n * Released under GPL v3 license.\n */\n".$rendered;
114 114
         }
115 115
 
116 116
         $response = new \Symfony\Component\HttpFoundation\Response($rendered);
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
         $info = $page->getBasicEditingInfo();
214 214
         $creationDateTime = DateTime::createFromFormat('YmdHis', $info['created_at']);
215 215
         $modifiedDateTime = DateTime::createFromFormat('YmdHis', $info['modified_at']);
216
-        $secsSinceLastEdit = (new DateTime)->getTimestamp() - $modifiedDateTime->getTimestamp();
216
+        $secsSinceLastEdit = (new DateTime)->getTimestamp()-$modifiedDateTime->getTimestamp();
217 217
 
218 218
         $data = [
219
-            'revisions' => (int) $info['num_edits'],
220
-            'editors' => (int) $info['num_editors'],
219
+            'revisions' => (int)$info['num_edits'],
220
+            'editors' => (int)$info['num_editors'],
221 221
             'author' => $info['author'],
222
-            'author_editcount' => (int) $info['author_editcount'],
222
+            'author_editcount' => (int)$info['author_editcount'],
223 223
             'created_at' => $creationDateTime->format('Y-m-d'),
224 224
             'created_rev_id' => $info['created_rev_id'],
225 225
             'modified_at' => $modifiedDateTime->format('Y-m-d H:i'),
226 226
             'secs_since_last_edit' => $secsSinceLastEdit,
227
-            'last_edit_id' => (int) $info['modified_rev_id'],
228
-            'watchers' => (int) $page->getWatchers(),
227
+            'last_edit_id' => (int)$info['modified_rev_id'],
228
+            'watchers' => (int)$page->getWatchers(),
229 229
             'pageviews' => $page->getLastPageviews($pageviewsOffset),
230 230
             'pageviews_offset' => $pageviewsOffset,
231 231
         ];
Please login to merge, or discard this patch.
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -8,15 +8,12 @@
 block discarded – undo
8 8
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9 9
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10 10
 use Symfony\Component\HttpFoundation\Request;
11
-use Symfony\Component\DependencyInjection\ContainerInterface;
12 11
 use Symfony\Component\HttpFoundation\Response;
13 12
 use Symfony\Component\HttpFoundation\JsonResponse;
14 13
 use Symfony\Component\HttpFoundation\RedirectResponse;
15 14
 use Symfony\Component\Process\Process;
16 15
 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
17 16
 use Xtools\ProjectRepository;
18
-use Xtools\Page;
19
-use Xtools\PagesRepository;
20 17
 use Xtools\ArticleInfo;
21 18
 use DateTime;
22 19
 
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -188,7 +188,7 @@
 block discarded – undo
188 188
      * @param Request $request The HTTP request.
189 189
      * @param string $project
190 190
      * @param string $article
191
-     * @return View
191
+     * @return Response
192 192
      * See ArticleInfoControllerTest::testArticleInfoApi()
193 193
      * @codeCoverageIgnore
194 194
      */
Please login to merge, or discard this patch.
src/Xtools/PagesRepository.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         // supply as the OFFSET.
149 149
         $limitClause = '';
150 150
         if (intval($limit) > 0 && isset($numRevisions)) {
151
-            $offset = $numRevisions - $limit;
151
+            $offset = $numRevisions-$limit;
152 152
             $limitClause = "LIMIT $offset, $limit";
153 153
         }
154 154
 
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
         $time2 = time();
265 265
 
266 266
         // If it took over 5 seconds, cache the result for 20 minutes.
267
-        if ($time2 - $time1 > 5) {
267
+        if ($time2-$time1 > 5) {
268 268
             $cacheItem = $this->cache->getItem($cacheKey)
269 269
                 ->set($result)
270 270
                 ->expiresAfter(new DateInterval('PT20M'));
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 
400 400
         $wikidataId = ltrim($page->getWikidataId(), 'Q');
401 401
 
402
-        $sql = "SELECT " . ($count ? 'COUNT(*) AS count' : '*') . "
402
+        $sql = "SELECT ".($count ? 'COUNT(*) AS count' : '*')."
403 403
                 FROM wikidatawiki_p.wb_items_per_site
404 404
                 WHERE ips_item_id = :wikidataId";
405 405
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 
410 410
         $result = $resultQuery->fetchAll();
411 411
 
412
-        return $count ? (int) $result[0]['count'] : $result;
412
+        return $count ? (int)$result[0]['count'] : $result;
413 413
     }
414 414
 
415 415
     /**
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
 
450 450
         // Transform to associative array by 'type'
451 451
         foreach ($res as $row) {
452
-            $data[$row['type'] . '_count'] = $row['value'];
452
+            $data[$row['type'].'_count'] = $row['value'];
453 453
         }
454 454
 
455 455
         return $data;
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 
488 488
         $project = $page->getProject()->getDomain();
489 489
 
490
-        $url = 'https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/' .
490
+        $url = 'https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/'.
491 491
             "$project/all-access/user/$title/daily/$start/$end";
492 492
 
493 493
         $res = $client->request('GET', $url);
Please login to merge, or discard this patch.