Completed
Push — master ( 56570e...2c8793 )
by Gabriel
07:17
created

ActionCallStage::hasInstanceAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nip\Dispatcher\Resolver\Pipeline\Stages;
4
5
use Nip\Controllers\Controller;
6
use Nip\Dispatcher\Exceptions\InvalidCommandException;
7
use Nip\Dispatcher\Resolver\ClassResolver\NameFormatter;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * Class ClassInstanceStage
13
 * @package Nip\Dispatcher\Resolver\Pipeline\Stages
14
 */
15
class ActionCallStage extends AbstractStage
16
{
17
    /**
18
     * @return void
19
     * @throws \Exception
20
     */
21 4 View Code Duplication
    public function processCommand()
0 ignored issues
show
Duplication introduced by
This method 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...
22
    {
23 4
        if (!$this->hasInstanceAction()) {
24 1
            throw new InvalidCommandException(
25
                "No valid instance for callback in dispatcher command " .
26 1
                "[" . print_r($this->getCommand(), true) . "]"
27
            );
28
        }
29
30 3
        $return = $this->invokeAction();
31 3
        $this->getCommand()->setReturn($return);
32 3
    }
33
34
    /**
35
     * @return ResponseInterface
36
     * @throws \Exception
37
     */
38 3
    protected function invokeAction()
39
    {
40
        /** @var Controller $controllerInstance */
41 3
        $controllerInstance = $this->getCommand()->getActionParam('instance');
42 3
        $controllerInstance->setRequest($this->getCommand()->getRequest());
43 3
        $action = $this->getCommand()->getActionParam('action');
44 3
        $method = NameFormatter::formatActionName($action);
45 3
        if (method_exists($controllerInstance, 'callAction')) {
46 3
            return $controllerInstance->callAction($method);
0 ignored issues
show
Documentation introduced by
$method is of type array<integer,string,{"0":"string"}>, but the function expects a boolean.

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...
47
        }
48
        return $controllerInstance->{$method}();
49
    }
50
}
51