Json   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 23
ccs 6
cts 7
cp 0.8571
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setContent() 0 4 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
 * 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