Completed
Pull Request — master (#90)
by Arnaud
03:24
created

ListAction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 95.45%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 6
dl 0
loc 64
ccs 21
cts 22
cp 0.9545
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setFilterFormBuilder() 0 4 1
B __invoke() 0 43 6
1
<?php
2
3
namespace LAG\AdminBundle\Action;
4
5
use LAG\AdminBundle\Filter\Factory\FilterFormBuilder;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
9
class ListAction extends Action
10
{
11
    /**
12
     * @var FilterFormBuilder
13
     */
14
    private $filterFormBuilder;
15
    
16
    /**
17
     * @param Request $request
18
     *
19
     * @return Response
20
     */
21 1
    public function __invoke(Request $request)
22
    {
23
        // build the filters form
24
        $filterForm = $this
25 1
            ->filterFormBuilder
26 1
            ->build($this->configuration)
27
        ;
28 1
        $filters = [];
29
30
        // load the filters
31 1
        if (null !== $filterForm) {
32 1
            $filterForm->handleRequest($request);
33
    
34 1
            if ($filterForm->isSubmitted() && $filterForm->isValid()) {
35
                $filters = $filterForm->getData();
36
            }
37
        }
38
        
39
        // load the entities
40
        $this
41 1
            ->admin
42 1
            ->handleRequest($request, $filters)
43
        ;
44
    
45
        $form = $this
46 1
            ->formFactory
47 1
            ->create(
48 1
                $this->configuration->getParameter('form'),
49 1
                $this->admin->getEntities(),
50 1
                $this->configuration->getParameter('form_options')
51
            )
52
        ;
53 1
        $form->handleRequest($request);
54
    
55 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...
56
            // TODO do something with the selected entities
57
        }
58
    
59
        return $this
0 ignored issues
show
Bug introduced by
The method respond does only exist in LAG\AdminBundle\Action\R...Responder\EditResponder, but not in LAG\AdminBundle\Action\R...nder\ResponderInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
60 1
            ->responder
61 1
            ->respond($this->configuration, $this->admin, $form, $filterForm)
0 ignored issues
show
Documentation introduced by
$filterForm is of type object<Symfony\Component\Form\FormInterface>|null, but the function expects a object<Symfony\Component\HttpFoundation\Request>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to DeleteResponder::respond() has too many arguments starting with $filterForm.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
62
        ;
63
    }
64
    
65
    /**
66
     * @param FilterFormBuilder $filterFormBuilder
67
     */
68 1
    public function setFilterFormBuilder($filterFormBuilder)
69
    {
70 1
        $this->filterFormBuilder = $filterFormBuilder;
71 1
    }
72
}
73