Completed
Pull Request — master (#90)
by Arnaud
02:15
created

ListAction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 96%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 7
dl 0
loc 81
ccs 24
cts 25
cp 0.96
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B __invoke() 0 43 6
1
<?php
2
3
namespace LAG\AdminBundle\Action;
4
5
use LAG\AdminBundle\Action\Responder\ListResponder;
6
use LAG\AdminBundle\Filter\Factory\FilterFormBuilder;
7
use Symfony\Component\Form\FormFactoryInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class ListAction extends Action
12
{
13
    /**
14
     * @var ListResponder
15
     */
16
    protected $responder;
17
    
18
    /**
19
     * @var FilterFormBuilder
20
     */
21
    protected $filterFormBuilder;
22
    
23
    /**
24
     * Action constructor.
25
     *
26
     * @param string               $name
27
     * @param FormFactoryInterface $formFactory
28
     * @param ListResponder        $responder
29
     * @param FilterFormBuilder    $filterFormBuilder
30
     */
31 1
    public function __construct(
32
        $name,
33
        FormFactoryInterface $formFactory,
34
        ListResponder $responder,
35
        FilterFormBuilder $filterFormBuilder
36
    ) {
37 1
        $this->name = $name;
38 1
        $this->formFactory = $formFactory;
39 1
        $this->responder = $responder;
40 1
        $this->filterFormBuilder = $filterFormBuilder;
41 1
    }
42
    
43
    /**
44
     * @param Request $request
45
     *
46
     * @return Response
47
     */
48 1
    public function __invoke(Request $request)
49
    {
50
        // build the filters form
51
        $filterForm = $this
52 1
            ->filterFormBuilder
53 1
            ->build($this->configuration)
54
        ;
55 1
        $filters = [];
56
57
        // load the filters
58 1
        if (null !== $filterForm) {
59 1
            $filterForm->handleRequest($request);
60
    
61 1
            if ($filterForm->isSubmitted() && $filterForm->isValid()) {
62
                $filters = $filterForm->getData();
63
            }
64
        }
65
        
66
        // load the entities
67
        $this
68 1
            ->admin
69 1
            ->handleRequest($request, $filters)
70
        ;
71
    
72
        $form = $this
73 1
            ->formFactory
74 1
            ->create(
75 1
                $this->configuration->getParameter('form'),
76 1
                $this->admin->getEntities(),
77 1
                $this->configuration->getParameter('form_options')
78
            )
79
        ;
80 1
        $form->handleRequest($request);
81
    
82 1
        if ($form->isSubmitted() && $form->isValid()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
83
            // TODO do something with the selected entities
84
        }
85
    
86
        return $this
87 1
            ->responder
88 1
            ->respond($this->configuration, $this->admin, $form, $filterForm)
89
        ;
90
    }
91
}
92