Json::output()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
1
<?php
2
3
namespace kalanis\kw_modules\Output;
4
5
6
/**
7
 * Class Json
8
 * @package kalanis\kw_modules
9
 * Output into Json
10
 */
11
class Json 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 array<string|int, string|int|float|array<string|int|float|array<string|int|float>>> $contentToEncode
18
     * @return $this
19
     */
20 1
    public function setContent($contentToEncode): self
21
    {
22 1
        $this->content = $contentToEncode;
23 1
        return $this;
24
    }
25
26 1
    public function output(): string
27
    {
28 1
        if (!headers_sent()) {
29
            // @codeCoverageIgnoreStart
30
            header('Content-Type: application/json');
31
        }
32
        // @codeCoverageIgnoreEnd
33 1
        return strval(json_encode($this->content));
34
    }
35
}
36