Completed
Push — master ( 6202fd...f9a3f2 )
by Sinnarasa
02:36
created

ClosureDispatcher::call()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 10
Code Lines 7

Duplication

Lines 2
Ratio 20 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 2
loc 10
rs 8.8571
cc 5
eloc 7
nc 12
nop 0
1
<?php
2
3
namespace JetFire\Routing\Dispatcher;
4
5
6
use JetFire\Routing\ResponseInterface;
7
use JetFire\Routing\Route;
8
9
/**
10
 * Class ClosureDispatcher
11
 * @package JetFire\Routing\Dispatcher
12
 */
13
class ClosureDispatcher implements DispatcherInterface
14
{
15
    /**
16
     * @var Route
17
     */
18
    private $route;
19
20
    /**
21
     * @var ResponseInterface
22
     */
23
    private $response;
24
25
    /**
26
     * @param Route $route
27
     */
28
    public function __construct(Route $route,ResponseInterface $response)
29
    {
30
        $this->route = $route;
31
        $this->response = $response;
32
    }
33
34
35
    /**
36
     * @description call anonymous function
37
     */
38
    public function call()
39
    {
40
        if ($this->response->getStatusCode() == 202) {
41
            $this->response->setStatusCode(200);
42
            $this->response->setHeaders(['Content-Type' => 'text/html']);
43
        }
44
        $params = ($this->route->getParameters() == '') ? [] : $this->route->getParameters();
45 View Code Duplication
        if(is_array($content = call_user_func_array($this->route->getTarget('closure'), $params))) $this->route->addTarget('data',$content);
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
46
        elseif(!is_null($content)) $this->response->setContent($content);
47
    }
48
49
}
50