BaseResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 6
eloc 10
dl 0
loc 58
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setMapper() 0 4 1
A __construct() 0 5 1
A getData() 0 3 1
A isPrettyPrint() 0 3 1
A setPrettyPrint() 0 4 1
A getContentType() 0 3 1
1
<?php
2
3
namespace kalanis\Restful\Application\Responses;
4
5
6
use kalanis\Restful\Mapping\IMapper;
7
use stdClass;
8
9
10
/**
11
 * BaseResponse
12
 * @package kalanis\Restful\Application\Responses
13
 */
14 1
abstract class BaseResponse implements IResponse
15
{
16
17
    /**
18
     * @var iterable<string|int, mixed>|stdClass
19
     */
20
    protected iterable|stdClass $data = [];
21
22
    private bool $prettyPrint = true;
23
24 1
    public function __construct(
25
        protected IMapper              $mapper,
26
        protected readonly string|null $contentType = null,
27
    )
28
    {
29 1
    }
30
31
    /**
32
     * Is pretty print enabled
33
     */
34
    public function isPrettyPrint(): bool
35
    {
36 1
        return $this->prettyPrint;
37
    }
38
39
    /**
40
     * Set pretty print
41
     */
42
    public function setPrettyPrint(bool $pretty): self
43
    {
44 1
        $this->prettyPrint = $pretty;
45 1
        return $this;
46
    }
47
48
    /**
49
     * Get response content type
50
     */
51
    public function getContentType(): ?string
52
    {
53 1
        return $this->contentType;
54
    }
55
56
    /**
57
     * Get response data
58
     * @return iterable<string|int, mixed>|stdClass|string
59
     */
60
    public function getData(): iterable|stdClass|string
61
    {
62
        return $this->data;
63
    }
64
65
    /**
66
     * Set mapper
67
     */
68
    public function setMapper(IMapper $mapper): self
69
    {
70
        $this->mapper = $mapper;
71
        return $this;
72
    }
73
}
74