Passed
Push — dev ( 65b5b3...c36508 )
by Marcin
04:08
created

BaseApiCodes::EX_AUTHENTICATION_EXCEPTION()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace MarcinOrlowski\ResponseBuilder;
5
6
/**
7
 * Laravel API Response Builder
8
 *
9
 * @package   MarcinOrlowski\ResponseBuilder
10
 *
11
 * @author    Marcin Orlowski <mail (#) marcinOrlowski (.) com>
12
 * @copyright 2016-2019 Marcin Orlowski
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
14
 * @link      https://github.com/MarcinOrlowski/laravel-api-response-builder
15
 */
16
17
/**
18
 * BaseApiCodes handling class
19
 */
20
class BaseApiCodes
21
{
22
    use ApiCodesHelpers;
23
24
    /**
25
     * protected code range - lowest code for reserved range.
26
     *
27
     * @var int
28
     */
29
    public const RESERVED_MIN_API_CODE_OFFSET = 0;
30
31
    /**
32
     * protected code range - highest code for reserved range
33
     *
34
     * @var int
35
     */
36
    public const RESERVED_MAX_API_CODE_OFFSET = 19;
37
38
    /**
39
     * built-in codes: OK
40
     *
41
     * @var int
42
     */
43
    protected const OK_OFFSET = 0;
44
    /**
45
     * built-in code for fallback message mapping
46
     *
47
     * @var int
48
     */
49
    protected const NO_ERROR_MESSAGE_OFFSET = 1;
50
    /**
51
     * built-in error code for HTTP_NOT_FOUND exception
52
     *
53
     * @var int
54
     */
55
    protected const EX_HTTP_NOT_FOUND_OFFSET = 10;
56
    /**
57
     * built-in error code for HTTP_SERVICE_UNAVAILABLE exception
58
     *
59
     * @var int
60
     */
61
    protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11;
62
    /**
63
     * built-in error code for HTTP_EXCEPTION
64
     *
65
     * @var int
66
     */
67
    protected const EX_HTTP_EXCEPTION_OFFSET = 12;
68
    /**
69
     * built-in error code for UNCAUGHT_EXCEPTION
70
     *
71
     * @var int
72
     */
73
    protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13;
74
75
    /**
76
     * built-in error code for \Illuminate\Auth\AuthenticationException
77
     *
78
     * @var int
79
     */
80
    protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14;
81
82
    /**
83
     * built-in error code for \Illuminate\Auth\AuthenticationException
84
     *
85
     * @var int
86
     */
87
    protected const EX_VALIDATION_EXCEPTION_OFFSET = 15;
88
89
    /**
90
     * Returns base code mapping array
91
     *
92
     * @return array
93
     */
94 81
    protected static function getBaseMap(): array
95
    {
96
        /**
97
         * @var array built-in codes mapping
98
         */
99
        return [
100 81
            self::OK()                          => 'response-builder::builder.ok',
101 81
            self::NO_ERROR_MESSAGE()            => 'response-builder::builder.no_error_message',
102 81
            self::EX_HTTP_NOT_FOUND()           => 'response-builder::builder.http_not_found',
103 81
            self::EX_HTTP_SERVICE_UNAVAILABLE() => 'response-builder::builder.http_service_unavailable',
104 81
            self::EX_HTTP_EXCEPTION()           => 'response-builder::builder.http_exception',
105 81
            self::EX_UNCAUGHT_EXCEPTION()       => 'response-builder::builder.uncaught_exception',
106 81
            self::EX_AUTHENTICATION_EXCEPTION() => 'response-builder::builder.authentication_exception',
107 81
            self::EX_VALIDATION_EXCEPTION()     => 'response-builder::builder.validation_exception',
108
        ];
109
    }
110
111
    /**
112
     * Returns API code for internal code OK
113
     *
114
     * @return int valid API code in current range
115
     */
116 81
    public static function OK(): int
117
    {
118 81
        return static::getCodeForInternalOffset(static::OK_OFFSET);
119
    }
120
121
    /**
122
     * Returns API code for internal code NO_ERROR_MESSAGE
123
     *
124
     * @return int valid API code in current range
125
     */
126 81
    public static function NO_ERROR_MESSAGE(): int
127
    {
128 81
        return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET);
129
    }
130
131
    /**
132
     * Returns API code for internal code EX_HTTP_NOT_FOUND
133
     *
134
     * @return int valid API code in current range
135
     */
136 81
    public static function EX_HTTP_NOT_FOUND(): int
137
    {
138 81
        return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET);
139
    }
140
141
    /**
142
     * Returns API code for internal code EX_HTTP_EXCEPTION
143
     *
144
     * @return int valid API code in current range
145
     */
146 81
    public static function EX_HTTP_EXCEPTION(): int
147
    {
148 81
        return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET);
149
    }
150
151
    /**
152
     * Returns API code for internal code EX_UNCAUGHT_EXCEPTION
153
     *
154
     * @return int valid API code in current range
155
     */
156 81
    public static function EX_UNCAUGHT_EXCEPTION(): int
157
    {
158 81
        return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET);
159
    }
160
161
    /**
162
     * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION
163
     *
164
     * @return int valid API code in current range
165
     */
166 81
    public static function EX_AUTHENTICATION_EXCEPTION(): int
167
    {
168 81
        return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET);
169
    }
170
171
    /**
172
     * Returns API code for internal code EX_VALIDATION_EXCEPTION
173
     *
174
     * @return int valid API code in current range
175
     */
176 81
    public static function EX_VALIDATION_EXCEPTION(): int
177
    {
178 81
        return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET);
179
    }
180
181
    /**
182
     * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE
183
     *
184
     * @return int valid API code in current range
185
     */
186 81
    public static function EX_HTTP_SERVICE_UNAVAILABLE(): int
187
    {
188 81
        return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET);
189
    }
190
191
}
192