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

JsonError   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 34
ccs 8
cts 9
cp 0.8889
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setContentStructure() 0 4 1
A setContent() 0 3 1
A output() 0 8 2
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