]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Factorize sendResponse between Api controllers
authorJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 24 Oct 2018 18:11:45 +0000 (20:11 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 22 Jan 2019 19:42:25 +0000 (20:42 +0100)
And run newer cs fixer

src/Wallabag/ApiBundle/Controller/EntryRestController.php
src/Wallabag/ApiBundle/Controller/SearchRestController.php
src/Wallabag/ApiBundle/Controller/WallabagRestController.php
tests/Wallabag/ApiBundle/Controller/SearchRestControllerTest.php

index f792aaf23a6afd53b6a3a498e992858fb73da1c1..a79e852cb0d833a3d00f522a0c037592ebb356c5 100644 (file)
@@ -4,7 +4,6 @@ namespace Wallabag\ApiBundle\Controller;
 
 use Hateoas\Configuration\Route;
 use Hateoas\Representation\Factory\PagerfantaFactory;
-use JMS\Serializer\SerializationContext;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\HttpFoundation\Request;
@@ -773,24 +772,6 @@ class EntryRestController extends WallabagRestController
         return $this->sendResponse($results);
     }
 
-    /**
-     * Shortcut to send data serialized in json.
-     *
-     * @param mixed $data
-     *
-     * @return JsonResponse
-     */
-    private function sendResponse($data)
-    {
-        // https://github.com/schmittjoh/JMSSerializerBundle/issues/293
-        $context = new SerializationContext();
-        $context->setSerializeNull(true);
-
-        $json = $this->get('jms_serializer')->serialize($data, 'json', $context);
-
-        return (new JsonResponse())->setJson($json);
-    }
-
     /**
      * Retrieve value from the request.
      * Used for POST & PATCH on a an entry.
index 6620107d36e76d8f774065c61b5515057cdeb412..f8da0ad4a28a179512199a5bd8d5183d84266b88 100644 (file)
@@ -4,7 +4,6 @@ namespace Wallabag\ApiBundle\Controller;
 
 use Hateoas\Configuration\Route;
 use Hateoas\Representation\Factory\PagerfantaFactory;
-use JMS\Serializer\SerializationContext;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Pagerfanta\Adapter\DoctrineORMAdapter;
 use Pagerfanta\Pagerfanta;
@@ -64,22 +63,4 @@ class SearchRestController extends WallabagRestController
 
         return $this->sendResponse($paginatedCollection);
     }
-
-    /**
-     * Shortcut to send data serialized in json.
-     *
-     * @param mixed $data
-     *
-     * @return JsonResponse
-     */
-    private function sendResponse($data)
-    {
-        // https://github.com/schmittjoh/JMSSerializerBundle/issues/293
-        $context = new SerializationContext();
-        $context->setSerializeNull(true);
-
-        $json = $this->get('jms_serializer')->serialize($data, 'json', $context);
-
-        return (new JsonResponse())->setJson($json);
-    }
 }
index 3c7ad0cfeb177a512906df28c971df82911ba710..f18b0910d9d05120b5eeee9ec108ed41190ac5a3 100644 (file)
@@ -3,6 +3,7 @@
 namespace Wallabag\ApiBundle\Controller;
 
 use FOS\RestBundle\Controller\FOSRestController;
+use JMS\Serializer\SerializationContext;
 use Nelmio\ApiDocBundle\Annotation\ApiDoc;
 use Symfony\Component\HttpFoundation\JsonResponse;
 use Symfony\Component\Security\Core\Exception\AccessDeniedException;
@@ -64,4 +65,22 @@ class WallabagRestController extends FOSRestController
             throw $this->createAccessDeniedException('Access forbidden. Entry user id: ' . $requestUserId . ', logged user id: ' . $user->getId());
         }
     }
+
+    /**
+     * Shortcut to send data serialized in json.
+     *
+     * @param mixed $data
+     *
+     * @return JsonResponse
+     */
+    protected function sendResponse($data)
+    {
+        // https://github.com/schmittjoh/JMSSerializerBundle/issues/293
+        $context = new SerializationContext();
+        $context->setSerializeNull(true);
+
+        $json = $this->get('jms_serializer')->serialize($data, 'json', $context);
+
+        return (new JsonResponse())->setJson($json);
+    }
 }
index f096f21b3cc4f603ade9116b8345ad2abf4581fd..fd5246393b31536d8a516fa7e0610c36d3c93d99 100644 (file)
@@ -3,7 +3,6 @@
 namespace Tests\Wallabag\ApiBundle\Controller;
 
 use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
-use Wallabag\CoreBundle\Entity\Entry;
 
 class SearchRestControllerTest extends WallabagApiTestCase
 {
@@ -19,7 +18,7 @@ class SearchRestControllerTest extends WallabagApiTestCase
 
         $content = json_decode($this->client->getResponse()->getContent(), true);
 
-        $this->assertGreaterThanOrEqual(1, count($content));
+        $this->assertGreaterThanOrEqual(1, \count($content));
         $this->assertArrayHasKey('items', $content['_embedded']);
         $this->assertGreaterThanOrEqual(0, $content['total']);
         $this->assertSame(1, $content['page']);
@@ -49,7 +48,7 @@ class SearchRestControllerTest extends WallabagApiTestCase
 
         $content = json_decode($this->client->getResponse()->getContent(), true);
 
-        $this->assertGreaterThanOrEqual(1, count($content));
+        $this->assertGreaterThanOrEqual(1, \count($content));
         $this->assertArrayHasKey('items', $content['_embedded']);
         $this->assertGreaterThanOrEqual(0, $content['total']);
         $this->assertSame(1, $content['page']);