Test Setup Failed
Push — master ( 8fa0e2...251f8c )
by Gabriel
08:50
created

MethodCallStage::hasInstanceAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Nip\Dispatcher\Resolver\Pipeline\Stages;
4
5
use Nip\Controllers\Controller;
6
use Nip\Dispatcher\Exceptions\InvalidCommandException;
7
use Psr\Http\Message\RequestInterface;
8
use Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * Class MethodCallStage
12
 * @package Nip\Dispatcher\Resolver\Pipeline\Stages
13
 */
14
class MethodCallStage extends AbstractStage
15
{
16
    /**
17
     * @return void
18
     * @throws \Exception
19
     */
20 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...
21
    {
22
        if (!$this->hasInstanceAction()) {
23
            throw new InvalidCommandException(
24
                "No valid instance for callback in dispatcher command " .
25
                "[" . print_r($this->getCommand(), true) . "]"
26
            );
27
        }
28
29
        $return = $this->callMethod();
30
        $this->getCommand()->setReturn($return);
31
    }
32
33
    /**
34
     * @return ResponseInterface
35
     * @throws \Exception
36
     */
37
    protected function callMethod()
38
    {
39
        /** @var Controller $controllerInstance */
40
        $controllerInstance = $this->getCommand()->getActionParam('instance');
41
        $controllerInstance->setRequest($this->getCommand()->getRequest());
42
        $method = $this->getCommand()->getActionParam('action');
43
        return $controllerInstance->{$method}();
44
    }
45
46
    /**
47
     * @return bool
48
     */
49
    protected function hasInstanceAction()
50
    {
51
        return $this->getCommand()->hasActionParam('instance');
52
    }
53
}