Test Failed
Push — master ( 85ca69...144c12 )
by Roman
15:41
created

FailedApiResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Crossword\Application\Response\API;
6
7
use App\Crossword\Application\Dto\ErrorDto;
8
use App\Crossword\Application\Enum\HttpStatusCode;
9
10
/**
11
 * @psalm-immutable
12
 */
13
final class FailedApiResponse implements ResponseInterface
14
{
15
    private int $status;
16
    private ErrorDto $error;
17
18
    public function __construct(ErrorDto $error, int $status = HttpStatusCode::HTTP_ERROR)
19
    {
20
        $this->status = $status;
21
        $this->error = $error;
22
    }
23
24
    /**
25
     * @psalm-suppress ImpureMethodCall
26
     */
27
    public function body(): array
28
    {
29
        return [
30
            'success' => false,
31
            'error' => $this->error->jsonSerialize(),
32
        ];
33
    }
34
35
    public function status(): int
36
    {
37
        return $this->status;
38
    }
39
}
40