ErrorResponse   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 6
dl 0
loc 45
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getContentType() 0 3 1
A getCode() 0 3 1
A send() 0 4 1
A getData() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
namespace kalanis\Restful\Application\Responses;
4
5
6
use Nette\Http;
7
use stdClass;
8
9
10
class ErrorResponse implements IResponse
11
{
12
13
    /**
14
     * @param IResponse $response Wrapped response with data
15
     */
16
    public function __construct(
17
        private readonly IResponse $response,
18
        private readonly int       $code = 500,
19
    )
20
    {
21
    }
22
23
    /**
24
     * Get response data
25
     * @return iterable<string|int, mixed>|stdClass|string
26
     */
27
    public function getData(): iterable|stdClass|string
28
    {
29
        return $this->response->getData();
30
    }
31
32
    /**
33
     * Get response content type
34
     */
35
    public function getContentType(): ?string
36
    {
37
        return $this->response->getContentType();
38
    }
39
40
    /**
41
     * Get response data
42
     */
43
    public function getCode(): int
44
    {
45
        return $this->code;
46
    }
47
48
    /**
49
     * Sends response to output
50
     */
51
    public function send(Http\IRequest $httpRequest, Http\IResponse $httpResponse): void
52
    {
53
        $httpResponse->setCode($this->code);
54
        $this->response->send($httpRequest, $httpResponse);
55
    }
56
}
57