Passed
Push — master ( 28b4dd...345bc1 )
by Petr
08:47
created

JsonError::setContentStructure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_modules\Output;
4
5
6
/**
7
 * Class Json
8
 * @package kalanis\kw_modules
9
 * Error Output into Json
10
 */
11
class JsonError extends AOutput
12
{
13
    /** @var array<string|int, string|int|float|array<string|int|float|array<string|int|float>>> */
14
    protected array $content = [];
15
16
    /**
17
     * @param string|int $code
18
     * @param string $message
19
     * @return $this
20
     */
21 1
    public function setContent($code, string $message): self
22
    {
23 1
        return $this->setContentStructure($code, $message);
24
    }
25
26
    /**
27
     * @param string|int $code
28
     * @param string|int|float|array<string|int|float|array<string|int|float>> $message
29
     * @return $this
30
     */
31 2
    public function setContentStructure($code, $message): self
32
    {
33 2
        $this->content = compact('code', 'message');
34 2
        return $this;
35
    }
36
37 2
    public function output(): string
38
    {
39 2
        if (!headers_sent()) {
40
            // @codeCoverageIgnoreStart
41
            header('Content-Type: application/json');
42
        }
43
        // @codeCoverageIgnoreEnd
44 2
        return strval(json_encode($this->content));
45
    }
46
}
47