Completed
Push — master ( 431275...4f28c1 )
by Nikola
05:08
created

ListController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 16.25 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 13
loc 80
ccs 20
cts 20
cp 1
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 13 13 2
A getRates() 0 13 3
A getFilterForm() 0 8 1
A getFilterFormType() 0 4 1
A getTwigTemplate() 0 4 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
 * This file is part of the Exchange Rate Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\ExchangeRate\Controller;
11
12
use RunOpenCode\Bundle\ExchangeRate\Form\FilterType;
13
use RunOpenCode\Bundle\ExchangeRate\Security\AccessVoter;
14
use RunOpenCode\ExchangeRate\Contract\RateInterface;
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Symfony\Component\Form\Form;
17
use Symfony\Component\HttpFoundation\Request;
18
19
/**
20
 * Class ListController
21
 *
22
 * @package RunOpenCode\Bundle\ExchangeRate\Controller
23
 */
24
class ListController extends Controller
25
{
26
    /**
27
     * Main controller action.
28
     *
29
     * @param Request $request
30
     *
31
     * @return \Symfony\Component\HttpFoundation\Response
32
     */
33 5 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...
34
    {
35 5
        if (!$this->isGranted(AccessVoter::VIEW, RateInterface::class)) {
36 1
            throw $this->createAccessDeniedException();
37
        }
38
39 4
        $filterForm = $this->getFilterForm($request);
40
41 4
        return $this->render($this->getTwigTemplate(), [
42 4
            'rates' => $this->getRates($filterForm),
43 4
            'form' => $filterForm->createView(),
44
        ]);
45
    }
46
47
    /**
48
     * Get rates for list view. Process filters if submitted.
49
     *
50
     * @param Form $filterForm
51
     *
52
     * @return \RunOpenCode\ExchangeRate\Contract\RateInterface[]
53
     */
54 4
    protected function getRates(Form $filterForm)
55
    {
56
        /**
57
         * @var \RunOpenCode\ExchangeRate\Contract\RepositoryInterface $repository
58
         */
59 4
        $repository = $this->get('runopencode.exchange_rate.repository');
60
61 4
        if ($filterForm->isSubmitted() && $filterForm->isValid()) {
62 1
            return $repository->all($filterForm->getData());
63
        }
64
65 4
        return $repository->all();
66
    }
67
68
    /**
69
     * Get filter form
70
     *
71
     * @param Request $request
72
     *
73
     * @return Form
74
     */
75 4
    protected function getFilterForm(Request $request)
76
    {
77 4
        $filter = $this->createForm($this->getFilterFormType());
78
79 4
        $filter->handleRequest($request);
80
81 4
        return $filter;
82
    }
83
84
    /**
85
     * Get FQCN of FilterType form.
86
     *
87
     * @return string
88
     */
89 4
    protected function getFilterFormType()
90
    {
91 4
        return FilterType::class;
92
    }
93
94
    /**
95
     * Get Twig template path.
96
     *
97
     * @return string
98
     */
99 4
    protected function getTwigTemplate()
100
    {
101 4
        return '@ExchangeRate/list.html.twig';
102
    }
103
}
104