Completed
Pull Request — master (#30)
by
unknown
03:43
created

UserController::listAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
1
<?php
2
3
namespace AppBundle\Controller\Api;
4
5
use AppBundle\Exception\JsonHttpException;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\Routing\Annotation\Route;
10
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
11
12
class UserController extends Controller
13
{
14
    /**
15
     * @Route("/users")
16
     *
17
     * @Method("GET")
18
     * @return JsonResponse
19
     */
20
    public function listAction()
21
    {
22
        $users = $this->getDoctrine()
23
            ->getRepository('AppBundle:User')
24
            ->findAll();
25
        if (!$users) {
26
            throw new JsonHttpException(404, 'User not found.');
27
        }
28
        return $this->json(['users' => $users], 200, [], [AbstractNormalizer::GROUPS => ['Short']]);
29
    }
30
}
31