ClosureStage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processCommand() 0 5 2
A isClosure() 0 3 1
A runClosure() 0 6 1
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