ApiResponseData   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 22
c 2
b 0
f 0
dl 0
loc 91
ccs 25
cts 25
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 7 1
A getErrorCode() 0 3 1
A getStatus() 0 3 1
A setErrorMessage() 0 4 1
A getData() 0 3 1
A setStatus() 0 4 1
A setData() 0 4 1
A getErrorMessage() 0 3 1
A setErrorCode() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Dto;
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 ApiResponseData
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 14
    public function getStatus(): string
73
    {
74 14
        return $this->status;
75
    }
76
77 14
    public function setStatus(string $status): self
78
    {
79 14
        $this->status = $status;
80 14
        return $this;
81
    }
82
83 14
    public function getErrorMessage(): string
84
    {
85 14
        return $this->errorMessage;
86
    }
87
88 7
    public function setErrorMessage(string $errorMessage): self
89
    {
90 7
        $this->errorMessage = $errorMessage;
91 7
        return $this;
92
    }
93
94 14
    public function getErrorCode(): ?int
95
    {
96 14
        return $this->errorCode;
97
    }
98
99 7
    public function setErrorCode(int $errorCode): self
100
    {
101 7
        $this->errorCode = $errorCode;
102 7
        return $this;
103
    }
104
105 14
    public function getData(): ?array
106
    {
107 14
        return $this->data;
108
    }
109
110 7
    public function setData(?array $data): self
111
    {
112 7
        $this->data = $data;
113 7
        return $this;
114
    }
115
116 14
    public function toArray(): array
117
    {
118
        return [
119 14
            'status' => $this->getStatus(),
120 14
            'error_message' => $this->getErrorMessage(),
121 14
            'error_code' => $this->getErrorCode(),
122 14
            'data' => $this->getData(),
123
        ];
124
    }
125
}
126