Completed
Pull Request — master (#90)
by Arnaud
21:22
created

ListAction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
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 86
ccs 0
cts 27
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 48 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
        dump($filterForm);
56
        $filters = [];
57
58
        // load the filters
59
        if (null !== $filterForm) {
60
            $filterForm->handleRequest($request);
61
    
62
            if ($filterForm->isSubmitted() && $filterForm->isValid()) {
63
                $filters = $filterForm->getData();
64
            }
65
        }
66
        
67
        // load the entities
68
        $this
69
            ->admin
70
            ->handleRequest($request, $filters)
71
        ;
72
    
73
        $form = $this
74
            ->formFactory
75
            ->create(
76
                $this->configuration->getParameter('form'),
77
                $this->admin->getEntities(),
78
                array_merge($this->configuration->getParameter('form_options'), [
79
                    'entities' => [
80
                    
81
                    ],
82
                ])
83
            )
84
        ;
85
        $form->handleRequest($request);
86
    
87
        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...
88
            // TODO do something with the selected entities
89
        }
90
    
91
        return $this
92
            ->responder
93
            ->respond($this->configuration, $this->admin, $form, $filterForm)
94
        ;
95
    }
96
}
97