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

CreateAction::__invoke()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 39
Code Lines 24

Duplication

Lines 39
Ratio 100 %

Code Coverage

Tests 15
CRAP Score 3.0146

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 39
loc 39
ccs 15
cts 17
cp 0.8824
rs 8.8571
cc 3
eloc 24
nc 2
nop 1
crap 3.0146
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 CreateAction 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
     * Create an action using the create action form 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
        $this
21 1
            ->admin
22 1
            ->handleRequest($request)
23
        ;
24
        // create the new entity
25
        $entity = $this
26 1
            ->admin
27 1
            ->create()
28
        ;
29
        // create the associated form type
30
        $formType = $this
31 1
            ->configuration
32 1
            ->getParameter('form')
33
        ;
34
        $formOptions = $this
35 1
            ->configuration
36 1
            ->getParameter('form_options')
37
        ;
38
        $form = $this
39 1
            ->formFactory
40 1
            ->create($formType, $entity, $formOptions)
41
        ;
42 1
        $form->handleRequest($request);
43
    
44 1
        if ($form->isSubmitted() && $form->isValid()) {
45
            $this
46
                ->admin
47
                ->save()
48
            ;
49
        }
50
    
51
        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...
52 1
            ->responder
53 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...
54
        ;
55
    }
56
}
57