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

UserController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A listAction() 0 10 2
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