RouterResponse::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 4
crap 1
1
<?php
2
/**
3
 * This file is part of the DS 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
 */
23
class RouterResponse implements RouterResponseInterface
24
{
25
    /**
26
     * @var int Response Status Code.
27
     */
28
    protected $statusCode;
29
30
    /**
31
     * @var string|\Closure Route Handler.
32
     */
33
    protected $handler;
34
35
    /**
36
     * @var array Route Query Params.
37
     */
38
    protected $vars = [];
39
40
    /**
41
     * @var array Route Names
42
     */
43
    protected $names = [];
44
45
    /**
46
     * Router Response constructor.
47
     *
48
     * @param int $statusCode
49
     * @param string|\Closure $handler
50
     * @param array $names
51
     * @param array $vars
52
     */
53 4
    public function __construct(
54
        $statusCode,
55
        $handler,
56
        array $names = [],
57
        array $vars = []
58
    )
59
    {
60 4
        $this->statusCode = $statusCode;
61 4
        $this->handler = $handler;
62 4
        $this->names = $names;
63 4
        $this->vars = $vars;
64 4
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 1
    public function getHandler()
70
    {
71 1
        return $this->handler;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 1
    public function getStatusCode()
78
    {
79 1
        return $this->statusCode;
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85 1
    public function getVars()
86
    {
87 1
        return $this->vars;
88
    }
89
90
    /**
91
     * @inheritdoc
92
     */
93 1
    public function getNames()
94
    {
95 1
        return $this->names;
96
    }
97
98
    /**
99
     * @param string $handler
100
     * @return RouterResponse
101
     */
102
    public function withHandler(string $handler){
103
        $new = clone $this;
104
        $new->handler = $handler;
105
        return $new;
106
    }
107
108
    /**
109
     * @param array $vars
110
     * @return RouterResponse
111
     */
112
    public function withVars(array $vars){
113
        $new = clone $this;
114
        $new->vars = $vars;
115
        return $new;
116
    }
117
118
    /**
119
     * @param int $code
120
     * @return RouterResponse
121
     */
122
    public function withStatusCode(int $code){
123
        $new = clone $this;
124
        $new->statusCode = $code;
125
        return $new;
126
    }
127
128
    /**
129
     * @param array $names
130
     * @return RouterResponse
131
     */
132
    public function withNames(array $names){
133
        $new = clone $this;
134
        $new->names = $names;
135
        return $new;
136
    }
137
}
138