ClosureStage::processCommand()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Nip\Dispatcher\Resolver\Pipeline\Stages;
4
5
use Closure;
6
use Nip\Http\Response\Response;
7
8
/**
9
 * Class ClosureStage
10
 * @package Nip\Dispatcher\Resolver\Pipeline\Stages
11
 */
12
class ClosureStage extends AbstractStage
13
{
14
    /**
15
     * @return void
16
     */
17 5
    public function processCommand()
18
    {
19 5
        if ($this->isClosure()) {
20 1
            $return = $this->runClosure();
21 1
            $this->getCommand()->setReturn($return);
22
        }
23 5
    }
24
25
    /**
26
     * @return bool
27
     */
28 5
    protected function isClosure()
29
    {
30 5
        return $this->getCommand()->getAction() instanceof Closure;
31
    }
32
33
    /**
34
     * Run the route action and return the response.
35
     *
36
     * @return mixed
37
     */
38 1
    protected function runClosure()
39
    {
40 1
        $closure = $this->getCommand()->getAction();
41 1
        return $closure(
42 1
            $this->getCommand()->getRequest(),
43 1
            new Response()
44
        );
45
    }
46
}
47