Completed
Pull Request — master (#30)
by
unknown
05:04
created

UserController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 52.63 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A listAction() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
    public function listAction()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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