Passed
Pull Request — master (#24)
by Alexander
03:14
created

ApiResponseData::setErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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