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

DeleteAction::__invoke()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 35
Code Lines 21

Duplication

Lines 35
Ratio 100 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 35
loc 35
ccs 15
cts 15
cp 1
rs 8.8571
cc 3
eloc 21
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 View Code Duplication
class DeleteAction extends Action
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * Delete an entity.
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
        $this
21 1
            ->admin
22 1
            ->handleRequest($request)
23
        ;
24
        // create the configured form type
25
        $formType = $this
26 1
            ->configuration
27 1
            ->getParameter('form')
28
        ;
29
        $formOptions = $this
30 1
            ->configuration
31 1
            ->getParameter('form_options')
32
        ;
33
        $form = $this
34 1
            ->formFactory
35 1
            ->create($formType, $this->admin->getUniqueEntity(), $formOptions)
36
        ;
37 1
        $form->handleRequest($request);
38
    
39 1
        if ($form->isSubmitted() && $form->isValid()) {
40
            // remove the entity
41
            $this
42 1
                ->admin
43 1
                ->remove()
44
            ;
45
        }
46
    
47
        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...
48 1
            ->responder
49 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...
50
        ;
51
    }
52
}
53