Test Failed
Pull Request — master (#87)
by Dmitriy
02:46
created

ApiResponse::getStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\Http\Response;
6
7
use OpenApi\Annotations as OA;
8
9
/**
10
 * @OA\Schema(
11
 *      schema="Response",
12
 * )
13
 * @OA\Schema(
14
 *      schema="BadResponse",
15
 *      allOf={
16
 *          @OA\Schema(ref="#/components/schemas/Response"),
17
 *          @OA\Schema(
18
 *              @OA\Property(
19
 *                  property="status",
20
 *                  example="failed",
21
 *              ),
22
 *              @OA\Property(property="error_message", example="Error description message"),
23
 *              @OA\Property(property="error_code", nullable=true, example=400),
24
 *              @OA\Property(
25
 *                  property="data",
26
 *                  example=null
27
 *              ),
28
 *          )
29
 *      }
30
 * )
31
 */
32
final class ApiResponse
33
{
34
    /**
35
     * @OA\Property(
36
     *      property="status",
37
     *      format="string",
38
     *      example="success",
39
     *      enum={"success", "failed"}
40
     * )
41
     */
42
    private string $status = '';
43
44
    /**
45
     * @OA\Property(
46
     *     property="error_message",
47
     *     format="string",
48
     *     example=""
49
     * )
50
     */
51
    private string $errorMessage = '';
52
53
    /**
54
     * @OA\Property(
55
     *     property="error_code",
56
     *     format="integer",
57
     *     nullable=true,
58
     *     example=null
59
     * )
60
     */
61
    private ?int $errorCode = null;
62
63
    /**
64
     * @OA\Property(
65
     *      property="data",
66
     *      type="object",
67
     *      nullable=true,
68
     * )
69
     */
70
    private ?array $data = null;
71
72
    public function getStatus(): string
73
    {
74
        return $this->status;
75
    }
76
77
    public function setStatus(string $status): self
78
    {
79
        $this->status = $status;
80
        return $this;
81
    }
82
83
    public function getErrorMessage(): string
84
    {
85
        return $this->errorMessage;
86
    }
87
88
    public function setErrorMessage(string $errorMessage): self
89
    {
90
        $this->errorMessage = $errorMessage;
91
        return $this;
92
    }
93
94
    public function getErrorCode(): ?int
95
    {
96
        return $this->errorCode;
97
    }
98
99
    public function setErrorCode(int $errorCode): self
100
    {
101
        $this->errorCode = $errorCode;
102
        return $this;
103
    }
104
105
    public function getData(): ?array
106
    {
107
        return $this->data;
108
    }
109
110
    public function setData(?array $data): self
111
    {
112
        $this->data = $data;
113
        return $this;
114
    }
115
116
    public function toArray(): array
117
    {
118
        return [
119
            'status' => $this->getStatus(),
120
            'data' => $this->getData(),
121
            'error_message' => $this->getErrorMessage(),
122
            'error_code' => $this->getErrorCode(),
123
        ];
124
    }
125
}
126