HttpResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 8
c 1
b 0
f 0
dl 0
loc 38
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 11 1
A sendHeaders() 0 3 2
A __toString() 0 3 1
A sendBody() 0 2 1
A __construct() 0 6 1
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