Test Failed
Push — master ( d4b731...813def )
by Dan
08:06
created

RouterResponse   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 0

Test Coverage

Coverage 46.67%

Importance

Changes 0
Metric Value
wmc 9
lcom 4
cbo 0
dl 0
loc 115
ccs 14
cts 30
cp 0.4667
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getHandler() 0 4 1
A getStatusCode() 0 4 1
A getVars() 0 4 1
A getNames() 0 4 1
A withHandler() 0 5 1
A withVars() 0 5 1
A withStatusCode() 0 5 1
A withNames() 0 5 1
1
<?php
2
/**
3
 * This file is part of the RS Framework.
4
 *
5
 * (c) Dan Smith <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Ds\Router;
11
12
use Ds\Router\Interfaces\RouterResponseInterface;
13
14
/**
15
 * RouterResponse Class.
16
 *
17
 * Contains information about matched Route.
18
 *
19
 * @package Ds\Router
20
 * @author  Dan Smith    <[email protected]>
21
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
22
 * @link    https://red-sqr.co.uk/Framework/Routercin/wikis/
23
 */
24
class RouterResponse implements RouterResponseInterface
25
{
26
    /**
27
     * @var int Response Status Code.
28
     */
29
    protected $statusCode;
30
31
    /**
32
     * @var string|\Closure Route Handler.
33
     */
34
    protected $handler;
35
36
    /**
37
     * @var array Route Query Params.
38
     */
39
    protected $vars = [];
40
41
    /**
42
     * @var array Route Names
43
     */
44
    protected $names = [];
45
46
    /**
47
     * Router Response constructor.
48
     *
49
     * @param int $statusCode
50
     * @param string|\Closure $handler
51
     * @param array $names
52
     * @param array $vars
53
     */
54 4
    public function __construct(
55
        $statusCode,
56
        $handler,
57
        array $names = [],
58
        array $vars = []
59
    )
60
    {
61 4
        $this->statusCode = $statusCode;
62 4
        $this->handler = $handler;
63 4
        $this->names = $names;
64 4
        $this->vars = $vars;
65 4
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70 1
    public function getHandler()
71
    {
72 1
        return $this->handler;
73
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78 1
    public function getStatusCode()
79
    {
80 1
        return $this->statusCode;
81
    }
82
83
    /**
84
     * @inheritdoc
85
     */
86 1
    public function getVars()
87
    {
88 1
        return $this->vars;
89
    }
90
91
    /**
92
     * @inheritdoc
93
     */
94 1
    public function getNames()
95
    {
96 1
        return $this->names;
97
    }
98
99
    /**
100
     * @param string $handler
101
     * @return RouterResponse
102
     */
103
    public function withHandler(string $handler){
104
        $new = clone $this;
105
        $new->handler = $handler;
106
        return $new;
107
    }
108
109
    /**
110
     * @param array $vars
111
     * @return RouterResponse
112
     */
113
    public function withVars(array $vars){
114
        $new = clone $this;
115
        $new->vars = $vars;
116
        return $new;
117
    }
118
119
    /**
120
     * @param int $code
121
     * @return RouterResponse
122
     */
123
    public function withStatusCode(int $code){
124
        $new = clone $this;
125
        $new->statusCode = $code;
126
        return $new;
127
    }
128
129
    /**
130
     * @param array $names
131
     * @return RouterResponse
132
     */
133
    public function withNames(array $names){
134
        $new = clone $this;
135
        $new->names = $names;
136
        return $new;
137
    }
138
}
139