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

FailedApiResponse   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 9
c 0
b 0
f 0
dl 0
loc 25
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A body() 0 5 1
A __construct() 0 4 1
A status() 0 3 1
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