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

ClosureDispatcher   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 5.41 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 6
c 3
b 0
f 1
lcom 1
cbo 2
dl 2
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B call() 2 10 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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