Json::setContent()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
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