Completed
Push — master ( 20e80f...9e4566 )
by Joachim
08:10
created

LabelController::newAction()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 101
Code Lines 68

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 101
rs 6.4589
c 0
b 0
f 0
cc 7
eloc 68
nc 6
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Loevgaard\PakkelabelsBundle\Controller;
4
5
use Doctrine\ORM\EntityManager;
6
use Loevgaard\PakkelabelsBundle\Entity\Label;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
13
/**
14
 * @Route("/label")
15
 */
16
class LabelController extends Controller
17
{
18
    /**
19
     * @Method("GET")
20
     * @Route("", name="loevgaard_pakkelabels_label_index")
21
     *
22
     * @param Request $request
23
     *
24
     * @return Response
25
     */
26 View Code Duplication
    public function indexAction(Request $request)
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...
27
    {
28
        $paginator  = $this->get('knp_paginator');
29
30
        /** @var EntityManager $em */
31
        $em = $this->get('doctrine')->getManager();
32
33
        $qb = $em->createQueryBuilder();
34
        $qb->select('l')
35
            ->from('LoevgaardPakkelabelsBundle:Label', 'l')
36
            ->orderBy('l.id', 'desc')
37
        ;
38
39
        /** @var Label[] $labels */
40
        $labels = $paginator->paginate(
41
            $qb,
42
            $request->query->getInt('page', 1),
43
            100
44
        );
45
46
        return $this->render('@LoevgaardPakkelabels/label/index.html.twig', [
47
            'labels' => $labels,
48
        ]);
49
    }
50
51
    /**
52
     * @Method("GET")
53
     * @Route("/{id}/show", name="loevgaard_pakkelabels_label_show")
54
     *
55
     * @param Label     $label
56
     *
57
     * @return Response
58
     */
59
    public function showAction(Label $label) : Response
60
    {
61
        return $this->render('@LoevgaardPakkelabels/label/show.html.twig', [
62
            'label' => $label,
63
        ]);
64
    }
65
}
66