HttpResponse::send()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Lepton\Http\Response;
4
5
class HttpResponse
6
{
7
8
    public function __construct(
9
        public $statusCode,
10
        public $body = '',
11
        public $headers = array()
12
        )
13
    {
14
    }
15
16
17
    public function sendHeaders(){
18
        foreach ($this->headers as $key => $value) {
19
            header("$key: $value");
20
        }
21
    }
22
23
    public function sendBody(){
24
        echo $this->body;
25
    }
26
27
    public function send()
28
    {
29
30
        // Send headers
31
        $this->sendHeaders();
32
33
        // Send response code
34
        http_response_code($this->statusCode);
35
36
        // Send response bod
37
        $this->sendBody();
38
    }
39
40
    public function __toString()
41
    {
42
        return $this->body;
43
    }
44
}
45