Response::getOutput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Zortje\MVC\Network;
5
6
use Zortje\MVC\Storage\Cookie\Cookie;
7
8
/**
9
 * Class Response
10
 *
11
 * @package Zortje\MVC\Network
12
 */
13
class Response
14
{
15
16
    /**
17
     * @var array HTTP headers
18
     */
19
    protected $headers = [];
20
21
    /**
22
     * @var Cookie
23
     */
24
    protected $cookie;
25
26
    /**
27
     * @var string Output
28
     */
29
    protected $output;
30
    
31
    /**
32
     * Response constructor.
33
     *
34
     * @param array       $headers
35
     * @param Cookie|null $cookie
36
     * @param string      $output
37
     */
38 1
    public function __construct(array $headers, Cookie $cookie = null, string $output)
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
39
    {
40 1
        $this->headers = $headers;
41 1
        $this->cookie  = $cookie;
42 1
        $this->output  = $output;
43 1
    }
44
45
    /**
46
     * Get response headers as an array, to be set in the index.php file
47
     *
48
     * ```
49
     * foreach ($response->getHeaders() as $header) {
50
     *     header($header);
51
     * }
52
     * ```
53
     *
54
     * @return array
55
     */
56 2
    public function getHeaders(): array
57
    {
58 2
        return $this->headers;
59
    }
60
61
    /**
62
     * Get response cookie, to be set in the index.php file
63
     *
64
     * ```
65
     * setcookie('token', $response->getCookie->getTokenString(), time() + 3600, '/', '', true, true);
66
     * ```
67
     *
68
     * @return Cookie|null
69
     */
70 3
    public function getCookie()
71
    {
72 3
        return $this->cookie;
73
    }
74
75
    /**
76
     * Get response output, to be echoed in the index.php file
77
     *
78
     * ```
79
     * echo $response->getOutput();
80
     * ```
81
     *
82
     * @return string
83
     */
84 2
    public function getOutput(): string
85
    {
86 2
        return $this->output;
87
    }
88
}
89