ApiResponseData   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 9
eloc 51
c 2
b 1
f 0
dl 0
loc 98
rs 10

9 Methods

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