Completed
Push — master ( 220ceb...ab9a78 )
by Sinnarasa
02:32
created

ClosureDispatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 7.14 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 2
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A call() 2 6 3

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\Route;
7
8
/**
9
 * Class ClosureDispatcher
10
 * @package JetFire\Routing\Dispatcher
11
 */
12
class ClosureDispatcher implements DispatcherInterface
13
{
14
15
    /**
16
     * @var Route
17
     */
18
    private $route;
19
20
    /**
21
     * @param Route $route
22
     */
23
    public function __construct(Route $route)
24
    {
25
        $this->route = $route;
26
    }
27
28
    /**
29
     * @description call anonymous function
30
     *
31
     */
32
    public function call()
33
    {
34 View Code Duplication
        if ($this->route->getResponse('code') == 202) $this->route->setResponse(['code' => 200, 'message' => 'OK', 'type' => 'text/html']);
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...
35
        $params = ($this->route->getParameters() == '') ? [] : $this->route->getParameters();
36
        echo call_user_func_array($this->route->getTarget('closure'), $params);
37
    }
38
39
}
40