Completed
Push — master ( dd5924...1cc36f )
by Joachim
62:06 queued 54:44
created

LabelController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 11
loc 55
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 11 11 1
A showAction() 0 6 1
A imageAction() 0 9 1

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 Loevgaard\PakkelabelsBundle\Controller;
4
5
use Loevgaard\PakkelabelsBundle\Entity\Label;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9
use Symfony\Component\HttpFoundation\BinaryFileResponse;
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
        $repos = $this->get('loevgaard_pakkelabels.label_repository');
29
30
        /** @var Label[] $countryMappings */
31
        $labels = $repos->findAllWithPaging($request->query->getInt('page', 1));
32
33
        return $this->render('@LoevgaardPakkelabels/label/index.html.twig', [
34
            'labels' => $labels,
35
        ]);
36
    }
37
38
    /**
39
     * @Method("GET")
40
     * @Route("/{id}/show", name="loevgaard_pakkelabels_label_show")
41
     *
42
     * @param Label $label
43
     *
44
     * @return Response
45
     */
46
    public function showAction(Label $label): Response
47
    {
48
        return $this->render('@LoevgaardPakkelabels/label/show.html.twig', [
49
            'label' => $label,
50
        ]);
51
    }
52
53
    /**
54
     * @Method("GET")
55
     * @Route("/{id}/image", name="loevgaard_pakkelabels_label_image")
56
     *
57
     * @param Label $label
58
     *
59
     * @return BinaryFileResponse
60
     */
61
    public function imageAction(Label $label): BinaryFileResponse
62
    {
63
        $labelFactory = $this->get('loevgaard_pakkelabels.label_file_factory');
64
65
        // @todo remember to catch exception, maybe create a new exception class
66
        $labelFile = $labelFactory->create($label, true);
67
68
        return new BinaryFileResponse($labelFile);
69
    }
70
}
71