Completed
Push — master ( e5d625...75cd3f )
by Nikola
04:18
created

ListController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 63
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 13 2
A getRates() 0 13 3
A getFilterForm() 0 8 1
A getFilterFormType() 0 4 1
1
<?php
2
3
namespace RunOpenCode\Bundle\ExchangeRate\Controller;
4
5
use RunOpenCode\Bundle\ExchangeRate\Form\FilterType;
6
use RunOpenCode\Bundle\ExchangeRate\Security\AccessVoter;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\Form\Form;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * Class ListController
13
 *
14
 * @package RunOpenCode\Bundle\ExchangeRate\Controller
15
 */
16
class ListController extends Controller
17
{
18
    public function indexAction(Request $request)
19
    {
20
        if (!$this->isGranted(AccessVoter::VIEW)) {
21
            throw $this->createAccessDeniedException();
22
        }
23
24
        $filterForm = $this->getFilterForm($request);
25
26
        return $this->render('@ExchangeRate/list.html.twig', [
27
            'rates' => $this->getRates($filterForm),
28
            'form' => $filterForm->createView(),
29
        ]);
30
    }
31
32
    /**
33
     * Get rates for list view. Process filters if submitted.
34
     *
35
     * @param Form $filterForm
36
     *
37
     * @return \RunOpenCode\ExchangeRate\Contract\RateInterface[]
38
     */
39
    protected function getRates(Form $filterForm)
40
    {
41
        /**
42
         * @var \RunOpenCode\ExchangeRate\Contract\RepositoryInterface $repository
43
         */
44
        $repository = $this->get('runopencode.exchange_rate.repository');
45
46
        if ($filterForm->isSubmitted() && $filterForm->isValid()) {
47
            return $repository->all($filterForm->getData());
48
        }
49
50
        return $repository->all();
51
    }
52
53
    /**
54
     * Get filter form
55
     *
56
     * @param Request $request
57
     *
58
     * @return Form
59
     */
60
    protected function getFilterForm(Request $request)
61
    {
62
        $filter = $this->createForm($this->getFilterFormType());
63
64
        $filter->handleRequest($request);
65
66
        return $filter;
67
    }
68
69
    /**
70
     * Get FQCN of FilterType form.
71
     *
72
     * @return string
73
     */
74
    protected function getFilterFormType()
75
    {
76
        return FilterType::class;
77
    }
78
}
79