Completed
Pull Request — master (#90)
by Arnaud
17:45
created

ListAction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 7
dl 0
loc 85
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B __invoke() 0 47 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
    public function __construct(
32
        $name,
33
        FormFactoryInterface $formFactory,
34
        ListResponder $responder,
35
        FilterFormBuilder $filterFormBuilder
36
    ) {
37
        $this->name = $name;
38
        $this->formFactory = $formFactory;
39
        $this->responder = $responder;
40
        $this->filterFormBuilder = $filterFormBuilder;
41
    }
42
    
43
    /**
44
     * @param Request $request
45
     *
46
     * @return Response
47
     */
48
    public function __invoke(Request $request)
49
    {
50
        // build the filters form
51
        $filterForm = $this
52
            ->filterFormBuilder
53
            ->build($this->configuration)
54
        ;
55
        $filters = [];
56
57
        // load the filters
58
        if (null !== $filterForm) {
59
            $filterForm->handleRequest($request);
60
    
61
            if ($filterForm->isSubmitted() && $filterForm->isValid()) {
62
                $filters = $filterForm->getData();
63
            }
64
        }
65
        
66
        // load the entities
67
        $this
68
            ->admin
69
            ->handleRequest($request, $filters)
70
        ;
71
    
72
        $form = $this
73
            ->formFactory
74
            ->create(
75
                $this->configuration->getParameter('form'),
76
                $this->admin->getEntities(),
77
                array_merge($this->configuration->getParameter('form_options'), [
78
                    'entities' => [
79
                    
80
                    ],
81
                ])
82
            )
83
        ;
84
        $form->handleRequest($request);
85
    
86
        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...
87
            // TODO do something with the selected entities
88
        }
89
    
90
        return $this
91
            ->responder
92
            ->respond($this->configuration, $this->admin, $form, $filterForm)
93
        ;
94
    }
95
}
96