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

ClosureDispatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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