Completed
Push — master ( d99d38...fc2b8b )
by Sebastian
02:26
created

ContentResponse   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A flush() 0 7 1
A getResponseCode() 0 4 1
1
<?php
2
namespace Kartenmacherei\RestFramework\Response;
3
4
use Kartenmacherei\RestFramework\Response\Content\Content;
5
6
class ContentResponse implements Response
7
{
8
    /**
9
     * @var Content
10
     */
11
    private $content;
12
13
    /**
14
     * @param Content $content
15
     */
16
    public function __construct(Content $content)
17
    {
18
        $this->content = $content;
19
    }
20
21
    public function flush()
22
    {
23
        http_response_code($this->getResponseCode());
24
        header((new HttpHeader('Content-Type', $this->content->getContentType()->asString()))->asString());
25
26
        print($this->content->asString());
27
    }
28
29
    /**
30
     * @return int
31
     */
32
    protected function getResponseCode(): int
33
    {
34
        return 200;
35
    }
36
37
}
38