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

EditAction::__invoke()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 32
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 18
cts 18
cp 1
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 18
nc 2
nop 1
crap 3
1
<?php
2
3
namespace LAG\AdminBundle\Action;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
8
class EditAction extends Action
9
{
10
    /**
11
     * Edit and update an entity using the EditForm handler.
12
     *
13
     * @param Request $request
14
     *
15
     * @return Response
16
     */
17 1
    public function __invoke(Request $request)
18
    {
19
        // the Admin with auto injected with the KernelSubscriber
20 1
        $this
21
            ->admin
22 1
            ->handleRequest($request)
23
        ;
24
        
25
        // create the associated form type
26 1
        $form = $this
27
            ->formFactory
28 1
            ->create(
29 1
                $this->configuration->getParameter('form'),
30 1
                $this->admin->getUniqueEntity(),
31 1
                $this->configuration->getParameter('form_options')
32 1
            )
33 1
        ;
34 1
        $form->handleRequest($request);
35
    
36 1
        if ($form->isSubmitted() && $form->isValid()) {
37
            // save the updated entity
38 1
            $this
39
                ->admin
40 1
                ->save()
41
            ;
42 1
        }
43
    
44 1
        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...
45
            ->responder
46 1
            ->respond($this->configuration, $this->admin, $form, $request)
0 ignored issues
show
Unused Code introduced by
The call to DeleteResponder::respond() has too many arguments starting with $request.

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...
47 1
        ;
48
    }
49
}
50