Completed
Pull Request — master (#2)
by René
04:42
created

Response   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 4
c 5
b 0
f 0
lcom 0
cbo 0
dl 0
loc 76
rs 10
ccs 11
cts 11
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getHeaders() 0 4 1
A getCookie() 0 4 1
A getOutput() 0 4 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 $cookie
36
     * @param string $output
37
     */
38 1
    public function __construct(array $headers, Cookie $cookie, string $output)
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
69
     */
70 2
    public function getCookie(): Cookie
71
    {
72 2
        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