@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * |
| 87 | 87 | * NOTE: not typehints due to compatibility with Laravel's method signature. |
| 88 | 88 | * @noinspection PhpMissingReturnTypeInspection |
| 89 | - * @noinspection ReturnTypeCanBeDeclaredInspection |
|
| 89 | + * @noinspection ReturnTypeCanBeDeclaredInspection |
|
| 90 | 90 | * @noinspection PhpMissingParamTypeInspection |
| 91 | 91 | */ |
| 92 | 92 | protected function mergeConfigFrom($path, $key) |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | Util::sortArrayByPri($merged_config['converter']['classes']); |
| 108 | 108 | |
| 109 | - $this->app['config']->set($key, $merged_config); |
|
| 110 | - } |
|
| 109 | + $this->app['config']->set($key, $merged_config); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | 112 | } |
@@ -161,7 +161,7 @@ |
||
| 161 | 161 | * @throws Ex\InvalidTypeException |
| 162 | 162 | */ |
| 163 | 163 | public static function assertIsType(string $var_name, $value, array $allowed_types, |
| 164 | - string $ex_class = Ex\InvalidTypeException::class): void |
|
| 164 | + string $ex_class = Ex\InvalidTypeException::class): void |
|
| 165 | 165 | { |
| 166 | 166 | // Type::EXISTING_CLASS is artificial type, so we need separate logic to handle it. |
| 167 | 167 | $tmp = $allowed_types; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @throws Ex\NotIntegerException |
| 93 | 93 | */ |
| 94 | 94 | public static function success($data = null, int $api_code = null, array $placeholders = null, |
| 95 | - int $http_code = null, int $json_opts = null): HttpResponse |
|
| 95 | + int $http_code = null, int $json_opts = null): HttpResponse |
|
| 96 | 96 | { |
| 97 | 97 | return static::asSuccess($api_code) |
| 98 | 98 | ->withData($data) |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @throws Ex\NotIntegerException |
| 128 | 128 | */ |
| 129 | 129 | public static function error(int $api_code, array $placeholders = null, $data = null, int $http_code = null, |
| 130 | - int $json_opts = null): HttpResponse |
|
| 130 | + int $json_opts = null): HttpResponse |
|
| 131 | 131 | { |
| 132 | 132 | return static::asError($api_code) |
| 133 | 133 | ->withPlaceholders($placeholders) |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | public function withJsonOptions(int $json_opts = null): self |
| 230 | 230 | { |
| 231 | 231 | Validator::assertIsType('json_opts', $json_opts, [Type::INTEGER, |
| 232 | - Type::NULL]); |
|
| 232 | + Type::NULL]); |
|
| 233 | 233 | $this->json_opts = $json_opts; |
| 234 | 234 | |
| 235 | 235 | return $this; |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | public function withDebugData(array $debug_data = null): self |
| 246 | 246 | { |
| 247 | 247 | Validator::assertIsType('$debug_data', $debug_data, [Type::ARRAY, |
| 248 | - Type::NULL]); |
|
| 248 | + Type::NULL]); |
|
| 249 | 249 | $this->debug_data = $debug_data; |
| 250 | 250 | |
| 251 | 251 | return $this; |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | public function withMessage(string $msg = null): self |
| 262 | 262 | { |
| 263 | 263 | Validator::assertIsType('message', $msg, [Type::STRING, |
| 264 | - Type::NULL]); |
|
| 264 | + Type::NULL]); |
|
| 265 | 265 | $this->message = $msg; |
| 266 | 266 | |
| 267 | 267 | return $this; |
@@ -360,8 +360,8 @@ discard block |
||
| 360 | 360 | * @noinspection PhpTooManyParametersInspection |
| 361 | 361 | */ |
| 362 | 362 | protected function make(bool $success, int $api_code, $msg_or_api_code, $data = null, |
| 363 | - int $http_code = null, array $placeholders = null, array $http_headers = null, |
|
| 364 | - int $json_opts = null, array $debug_data = null): HttpResponse |
|
| 363 | + int $http_code = null, array $placeholders = null, array $http_headers = null, |
|
| 364 | + int $json_opts = null, array $debug_data = null): HttpResponse |
|
| 365 | 365 | { |
| 366 | 366 | $http_headers = $http_headers ?? []; |
| 367 | 367 | $http_code = $http_code ?? ($success ? RB::DEFAULT_HTTP_CODE_OK : RB::DEFAULT_HTTP_CODE_ERROR); |
@@ -405,8 +405,8 @@ discard block |
||
| 405 | 405 | * @noinspection PhpTooManyParametersInspection |
| 406 | 406 | */ |
| 407 | 407 | protected function buildResponse(bool $success, int $api_code, |
| 408 | - $msg_or_api_code, array $placeholders = null, |
|
| 409 | - $data = null, array $debug_data = null): array |
|
| 408 | + $msg_or_api_code, array $placeholders = null, |
|
| 409 | + $data = null, array $debug_data = null): array |
|
| 410 | 410 | { |
| 411 | 411 | // ensure $data is either @null, array or object of class with configured mapping. |
| 412 | 412 | $data = (new Converter())->convert($data); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @throws Ex\ArrayWithMixedKeysException |
| 98 | 98 | */ |
| 99 | 99 | protected static function processException(\Throwable $ex, array $ex_cfg, |
| 100 | - int $fallback_http_code = HttpResponse::HTTP_INTERNAL_SERVER_ERROR) |
|
| 100 | + int $fallback_http_code = HttpResponse::HTTP_INTERNAL_SERVER_ERROR) |
|
| 101 | 101 | { |
| 102 | 102 | $api_code = $ex_cfg['api_code']; |
| 103 | 103 | $http_code = $ex_cfg['http_code'] ?? $fallback_http_code; |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @noinspection PhpMissingParamTypeInspection |
| 196 | 196 | */ |
| 197 | 197 | protected function unauthenticated(/** @scrutinizer ignore-unused */ $request, |
| 198 | - AuthException $exception): HttpResponse |
|
| 198 | + AuthException $exception): HttpResponse |
|
| 199 | 199 | { |
| 200 | 200 | $cfg = self::getExceptionHandlerConfig(); |
| 201 | 201 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | * @throws Ex\NotIntegerException |
| 228 | 228 | */ |
| 229 | 229 | protected static function error(Throwable $ex, |
| 230 | - int $api_code, int $http_code = null, string $error_message = null): HttpResponse |
|
| 230 | + int $api_code, int $http_code = null, string $error_message = null): HttpResponse |
|
| 231 | 231 | { |
| 232 | 232 | $ex_http_code = ($ex instanceof HttpException) ? $ex->getStatusCode() : $ex->getCode(); |
| 233 | 233 | $http_code = $http_code ?? $ex_http_code; |
@@ -22,72 +22,72 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class BaseApiCodes |
| 24 | 24 | { |
| 25 | - use ApiCodesHelpers; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * protected code range - lowest code for reserved range. |
|
| 29 | - * |
|
| 30 | - * @var int |
|
| 31 | - */ |
|
| 32 | - public const RESERVED_MIN_API_CODE_OFFSET = 0; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * protected code range - highest code for reserved range |
|
| 36 | - * |
|
| 37 | - * @var int |
|
| 38 | - */ |
|
| 39 | - public const RESERVED_MAX_API_CODE_OFFSET = 19; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * built-in codes: OK |
|
| 43 | - * |
|
| 44 | - * @var int |
|
| 45 | - */ |
|
| 46 | - protected const OK_OFFSET = 0; |
|
| 47 | - /** |
|
| 48 | - * built-in code for fallback message mapping |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - protected const NO_ERROR_MESSAGE_OFFSET = 1; |
|
| 53 | - /** |
|
| 54 | - * built-in error code for HTTP_NOT_FOUND exception |
|
| 55 | - * |
|
| 56 | - * @var int |
|
| 57 | - */ |
|
| 58 | - protected const EX_HTTP_NOT_FOUND_OFFSET = 10; |
|
| 59 | - /** |
|
| 60 | - * built-in error code for HTTP_SERVICE_UNAVAILABLE exception |
|
| 61 | - * |
|
| 62 | - * @var int |
|
| 63 | - */ |
|
| 64 | - protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11; |
|
| 65 | - /** |
|
| 66 | - * built-in error code for HTTP_EXCEPTION |
|
| 67 | - * |
|
| 68 | - * @var int |
|
| 69 | - */ |
|
| 70 | - protected const EX_HTTP_EXCEPTION_OFFSET = 12; |
|
| 71 | - /** |
|
| 72 | - * built-in error code for UNCAUGHT_EXCEPTION |
|
| 73 | - * |
|
| 74 | - * @var int |
|
| 75 | - */ |
|
| 76 | - protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * built-in error code for \Illuminate\Auth\AuthenticationException |
|
| 80 | - * |
|
| 81 | - * @var int |
|
| 82 | - */ |
|
| 83 | - protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * built-in error code for \Illuminate\Auth\AuthenticationException |
|
| 87 | - * |
|
| 88 | - * @var int |
|
| 89 | - */ |
|
| 90 | - protected const EX_VALIDATION_EXCEPTION_OFFSET = 15; |
|
| 25 | + use ApiCodesHelpers; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * protected code range - lowest code for reserved range. |
|
| 29 | + * |
|
| 30 | + * @var int |
|
| 31 | + */ |
|
| 32 | + public const RESERVED_MIN_API_CODE_OFFSET = 0; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * protected code range - highest code for reserved range |
|
| 36 | + * |
|
| 37 | + * @var int |
|
| 38 | + */ |
|
| 39 | + public const RESERVED_MAX_API_CODE_OFFSET = 19; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * built-in codes: OK |
|
| 43 | + * |
|
| 44 | + * @var int |
|
| 45 | + */ |
|
| 46 | + protected const OK_OFFSET = 0; |
|
| 47 | + /** |
|
| 48 | + * built-in code for fallback message mapping |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + protected const NO_ERROR_MESSAGE_OFFSET = 1; |
|
| 53 | + /** |
|
| 54 | + * built-in error code for HTTP_NOT_FOUND exception |
|
| 55 | + * |
|
| 56 | + * @var int |
|
| 57 | + */ |
|
| 58 | + protected const EX_HTTP_NOT_FOUND_OFFSET = 10; |
|
| 59 | + /** |
|
| 60 | + * built-in error code for HTTP_SERVICE_UNAVAILABLE exception |
|
| 61 | + * |
|
| 62 | + * @var int |
|
| 63 | + */ |
|
| 64 | + protected const EX_HTTP_SERVICE_UNAVAILABLE_OFFSET = 11; |
|
| 65 | + /** |
|
| 66 | + * built-in error code for HTTP_EXCEPTION |
|
| 67 | + * |
|
| 68 | + * @var int |
|
| 69 | + */ |
|
| 70 | + protected const EX_HTTP_EXCEPTION_OFFSET = 12; |
|
| 71 | + /** |
|
| 72 | + * built-in error code for UNCAUGHT_EXCEPTION |
|
| 73 | + * |
|
| 74 | + * @var int |
|
| 75 | + */ |
|
| 76 | + protected const EX_UNCAUGHT_EXCEPTION_OFFSET = 13; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * built-in error code for \Illuminate\Auth\AuthenticationException |
|
| 80 | + * |
|
| 81 | + * @var int |
|
| 82 | + */ |
|
| 83 | + protected const EX_AUTHENTICATION_EXCEPTION_OFFSET = 14; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * built-in error code for \Illuminate\Auth\AuthenticationException |
|
| 87 | + * |
|
| 88 | + * @var int |
|
| 89 | + */ |
|
| 90 | + protected const EX_VALIDATION_EXCEPTION_OFFSET = 15; |
|
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * Returns base code mapping array |
@@ -100,21 +100,21 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @noinspection PhpUnhandledExceptionInspection |
| 102 | 102 | */ |
| 103 | - protected static function getBaseMap(): array |
|
| 104 | - { |
|
| 105 | - $tpl = 'response-builder::builder.http_%d'; |
|
| 106 | - |
|
| 107 | - return [ |
|
| 108 | - self::OK() => 'response-builder::builder.ok', |
|
| 109 | - self::NO_ERROR_MESSAGE() => 'response-builder::builder.no_error_message', |
|
| 110 | - self::EX_HTTP_EXCEPTION() => 'response-builder::builder.http_exception', |
|
| 111 | - self::EX_UNCAUGHT_EXCEPTION() => 'response-builder::builder.uncaught_exception', |
|
| 112 | - self::EX_HTTP_NOT_FOUND() => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND), |
|
| 113 | - self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE), |
|
| 114 | - self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED), |
|
| 115 | - self::EX_VALIDATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY), |
|
| 116 | - ]; |
|
| 117 | - } |
|
| 103 | + protected static function getBaseMap(): array |
|
| 104 | + { |
|
| 105 | + $tpl = 'response-builder::builder.http_%d'; |
|
| 106 | + |
|
| 107 | + return [ |
|
| 108 | + self::OK() => 'response-builder::builder.ok', |
|
| 109 | + self::NO_ERROR_MESSAGE() => 'response-builder::builder.no_error_message', |
|
| 110 | + self::EX_HTTP_EXCEPTION() => 'response-builder::builder.http_exception', |
|
| 111 | + self::EX_UNCAUGHT_EXCEPTION() => 'response-builder::builder.uncaught_exception', |
|
| 112 | + self::EX_HTTP_NOT_FOUND() => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND), |
|
| 113 | + self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE), |
|
| 114 | + self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED), |
|
| 115 | + self::EX_VALIDATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY), |
|
| 116 | + ]; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Returns API code for internal code OK |
@@ -127,10 +127,10 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @noinspection PhpMethodNamingConventionInspection |
| 129 | 129 | */ |
| 130 | - public static function OK(): int |
|
| 131 | - { |
|
| 132 | - return static::getCodeForInternalOffset(static::OK_OFFSET); |
|
| 133 | - } |
|
| 130 | + public static function OK(): int |
|
| 131 | + { |
|
| 132 | + return static::getCodeForInternalOffset(static::OK_OFFSET); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Returns API code for internal code NO_ERROR_MESSAGE |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @noinspection PhpMethodNamingConventionInspection |
| 145 | 145 | */ |
| 146 | - public static function NO_ERROR_MESSAGE(): int |
|
| 147 | - { |
|
| 148 | - return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET); |
|
| 149 | - } |
|
| 146 | + public static function NO_ERROR_MESSAGE(): int |
|
| 147 | + { |
|
| 148 | + return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | /** |
| 152 | 152 | * Returns API code for internal code EX_HTTP_NOT_FOUND |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @noinspection PhpMethodNamingConventionInspection |
| 161 | 161 | */ |
| 162 | - public static function EX_HTTP_NOT_FOUND(): int |
|
| 163 | - { |
|
| 164 | - return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET); |
|
| 165 | - } |
|
| 162 | + public static function EX_HTTP_NOT_FOUND(): int |
|
| 163 | + { |
|
| 164 | + return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * Returns API code for internal code EX_HTTP_EXCEPTION |
@@ -175,10 +175,10 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @noinspection PhpMethodNamingConventionInspection |
| 177 | 177 | */ |
| 178 | - public static function EX_HTTP_EXCEPTION(): int |
|
| 179 | - { |
|
| 180 | - return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET); |
|
| 181 | - } |
|
| 178 | + public static function EX_HTTP_EXCEPTION(): int |
|
| 179 | + { |
|
| 180 | + return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | 184 | * Returns API code for internal code EX_UNCAUGHT_EXCEPTION |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @noinspection PhpMethodNamingConventionInspection |
| 193 | 193 | */ |
| 194 | - public static function EX_UNCAUGHT_EXCEPTION(): int |
|
| 195 | - { |
|
| 196 | - return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET); |
|
| 197 | - } |
|
| 194 | + public static function EX_UNCAUGHT_EXCEPTION(): int |
|
| 195 | + { |
|
| 196 | + return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | 200 | * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION |
@@ -207,10 +207,10 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @noinspection PhpMethodNamingConventionInspection |
| 209 | 209 | */ |
| 210 | - public static function EX_AUTHENTICATION_EXCEPTION(): int |
|
| 211 | - { |
|
| 212 | - return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET); |
|
| 213 | - } |
|
| 210 | + public static function EX_AUTHENTICATION_EXCEPTION(): int |
|
| 211 | + { |
|
| 212 | + return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | 216 | * Returns API code for internal code EX_VALIDATION_EXCEPTION |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | * |
| 224 | 224 | * @noinspection PhpMethodNamingConventionInspection |
| 225 | 225 | */ |
| 226 | - public static function EX_VALIDATION_EXCEPTION(): int |
|
| 227 | - { |
|
| 228 | - return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET); |
|
| 229 | - } |
|
| 226 | + public static function EX_VALIDATION_EXCEPTION(): int |
|
| 227 | + { |
|
| 228 | + return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | 231 | /** |
| 232 | 232 | * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE |
@@ -239,9 +239,9 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @noinspection PhpMethodNamingConventionInspection |
| 241 | 241 | */ |
| 242 | - public static function EX_HTTP_SERVICE_UNAVAILABLE(): int |
|
| 243 | - { |
|
| 244 | - return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET); |
|
| 245 | - } |
|
| 242 | + public static function EX_HTTP_SERVICE_UNAVAILABLE(): int |
|
| 243 | + { |
|
| 244 | + return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | 247 | } |
@@ -34,10 +34,10 @@ |
||
| 34 | 34 | * |
| 35 | 35 | * @throws Ex\InvalidTypeException |
| 36 | 36 | */ |
| 37 | - public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array |
|
| 38 | - { |
|
| 39 | - Validator::assertIsObject('obj', $obj); |
|
| 37 | + public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array |
|
| 38 | + { |
|
| 39 | + Validator::assertIsObject('obj', $obj); |
|
| 40 | 40 | |
| 41 | - return $obj->toArray(null); |
|
| 42 | - } |
|
| 41 | + return $obj->toArray(null); |
|
| 42 | + } |
|
| 43 | 43 | } |