Passed
Push — master ( b8f6df...218d14 )
by Alexander
01:42
created

Html::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace alkemann\h2l\response;
4
5
use alkemann\h2l\Message;
6
use alkemann\h2l\Response;
7
use alkemann\h2l\util\Http;
8
9
/**
10
 * Class Html
11
 *
12
 * @package alkemann\h2l
13
 */
14
class Html extends Response
15
{
16
    /**
17
     * @param string $content HTML
18
     * @param int $code HTTP code to respond with, defaults to `200`
19
     * @param array $config inject config/overrides like `header_func`
20
     */
21
    public function __construct($content = null, int $code = Http::CODE_OK, array $config = [])
22
    {
23
        $this->config = $config;
24
        $this->message = (new Message())
25
            ->withCode($code)
26
            ->withHeaders([
27
                'Content-Type' => Http::CONTENT_HTML
28
            ])
29
            ->withBody($content)
0 ignored issues
show
Bug introduced by
It seems like $content can also be of type null; however, parameter $body of alkemann\h2l\Message::withBody() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            ->withBody(/** @scrutinizer ignore-type */ $content)
Loading history...
30
        ;
31
    }
32
33
    /**
34
     * Set header and return a string rendered and ready to be echo'ed as response
35
     *
36
     * Header 'Content-type:' will be set using `header` or an injeced 'header_func' through constructor
37
     */
38
    public function render(): string
39
    {
40
        $this->setHeaders();
41
        return $this->message->body();
42
    }
43
}
44