Completed
Pull Request — dev (#22)
by
unknown
03:39
created

UserController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A listAction() 0 10 2
1
<?php
2
3
namespace AppBundle\Controller\Api;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
6
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $users of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
26
            throw new NotFoundHttpException();
27
        }
28
        return $this->json(['users' => $users], 200, [], [AbstractNormalizer::GROUPS => ['Short']]);
29
    }
30
}
31