@@ -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 | } |
@@ -47,12 +47,12 @@ |
||
| 47 | 47 | |
| 48 | 48 | /** @var \Symfony\Component\HttpKernel\Exception\HttpException $ex */ |
| 49 | 49 | $http_code = $ex->getStatusCode(); |
| 50 | - $result = $config[ $http_code ] ?? null; |
|
| 50 | + $result = $config[$http_code] ?? null; |
|
| 51 | 51 | |
| 52 | 52 | // If we do not have dedicated entry fort this particular http_code, |
| 53 | 53 | // fall back to default value. |
| 54 | 54 | if ($result === null) { |
| 55 | - $result = $config[ RB::KEY_DEFAULT ]; |
|
| 55 | + $result = $config[RB::KEY_DEFAULT]; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Some defaults to fall back to if not set in user config. |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @throws Ex\ArrayWithMixedKeysException |
| 91 | 91 | */ |
| 92 | 92 | public static function success($data = null, int $api_code = null, array $placeholders = null, |
| 93 | - int $http_code = null, int $json_opts = null): HttpResponse |
|
| 93 | + int $http_code = null, int $json_opts = null): HttpResponse |
|
| 94 | 94 | { |
| 95 | 95 | return static::asSuccess($api_code) |
| 96 | 96 | ->withData($data) |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @throws Ex\ArrayWithMixedKeysException |
| 124 | 124 | */ |
| 125 | 125 | public static function error(int $api_code, array $placeholders = null, $data = null, int $http_code = null, |
| 126 | - int $json_opts = null): HttpResponse |
|
| 126 | + int $json_opts = null): HttpResponse |
|
| 127 | 127 | { |
| 128 | 128 | return static::asError($api_code) |
| 129 | 129 | ->withPlaceholders($placeholders) |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | public function withJsonOptions(int $json_opts = null): self |
| 216 | 216 | { |
| 217 | 217 | Validator::assertIsType('json_opts', $json_opts, [Type::INTEGER, |
| 218 | - Type::NULL]); |
|
| 218 | + Type::NULL]); |
|
| 219 | 219 | $this->json_opts = $json_opts; |
| 220 | 220 | |
| 221 | 221 | return $this; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | public function withDebugData(array $debug_data = null): self |
| 230 | 230 | { |
| 231 | 231 | Validator::assertIsType('$debug_data', $debug_data, [Type::ARRAY, |
| 232 | - Type::NULL]); |
|
| 232 | + Type::NULL]); |
|
| 233 | 233 | $this->debug_data = $debug_data; |
| 234 | 234 | |
| 235 | 235 | return $this; |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | public function withMessage(string $msg = null): self |
| 244 | 244 | { |
| 245 | 245 | Validator::assertIsType('message', $msg, [Type::STRING, |
| 246 | - Type::NULL]); |
|
| 246 | + Type::NULL]); |
|
| 247 | 247 | $this->message = $msg; |
| 248 | 248 | |
| 249 | 249 | return $this; |
@@ -338,8 +338,8 @@ discard block |
||
| 338 | 338 | * @noinspection PhpTooManyParametersInspection |
| 339 | 339 | */ |
| 340 | 340 | protected function make(bool $success, int $api_code, $msg_or_api_code, $data = null, |
| 341 | - int $http_code = null, array $placeholders = null, array $http_headers = null, |
|
| 342 | - int $json_opts = null, array $debug_data = null): HttpResponse |
|
| 341 | + int $http_code = null, array $placeholders = null, array $http_headers = null, |
|
| 342 | + int $json_opts = null, array $debug_data = null): HttpResponse |
|
| 343 | 343 | { |
| 344 | 344 | $http_headers = $http_headers ?? []; |
| 345 | 345 | $http_code = $http_code ?? ($success ? RB::DEFAULT_HTTP_CODE_OK : RB::DEFAULT_HTTP_CODE_ERROR); |
@@ -384,8 +384,8 @@ discard block |
||
| 384 | 384 | * @noinspection PhpTooManyParametersInspection |
| 385 | 385 | */ |
| 386 | 386 | protected function buildResponse(bool $success, int $api_code, |
| 387 | - $msg_or_api_code, array $placeholders = null, |
|
| 388 | - $data = null, array $debug_data = null): array |
|
| 387 | + $msg_or_api_code, array $placeholders = null, |
|
| 388 | + $data = null, array $debug_data = null): array |
|
| 389 | 389 | { |
| 390 | 390 | // ensure $data is either @null, array or object of class with configured mapping. |
| 391 | 391 | $data = (new Converter())->convert($data); |
@@ -391,11 +391,11 @@ discard block |
||
| 391 | 391 | $data = (new Converter())->convert($data); |
| 392 | 392 | if ($data !== null) { |
| 393 | 393 | // ensure we get object in final JSON structure in data node |
| 394 | - $data = (object)$data; |
|
| 394 | + $data = (object) $data; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | if ($data === null && Config::get(RB::CONF_KEY_DATA_ALWAYS_OBJECT, false)) { |
| 398 | - $data = (object)[]; |
|
| 398 | + $data = (object) []; |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | // get human readable message for API code or use message string (if given instead of API code) |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | |
| 418 | 418 | if ($debug_data !== null) { |
| 419 | 419 | $debug_key = Config::get(RB::CONF_KEY_DEBUG_DEBUG_KEY, RB::KEY_DEBUG); |
| 420 | - $response[ $debug_key ] = $debug_data; |
|
| 420 | + $response[$debug_key] = $debug_data; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | return $response; |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @throws Ex\ArrayWithMixedKeysException |
| 95 | 95 | */ |
| 96 | 96 | protected static function processException(\Throwable $ex, array $ex_cfg, |
| 97 | - int $fallback_http_code = HttpResponse::HTTP_INTERNAL_SERVER_ERROR) |
|
| 97 | + int $fallback_http_code = HttpResponse::HTTP_INTERNAL_SERVER_ERROR) |
|
| 98 | 98 | { |
| 99 | 99 | $api_code = $ex_cfg['api_code']; |
| 100 | 100 | $http_code = $ex_cfg['http_code'] ?? $fallback_http_code; |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @throws Ex\ArrayWithMixedKeysException |
| 179 | 179 | */ |
| 180 | 180 | protected function unauthenticated(/** @scrutinizer ignore-unused */ $request, |
| 181 | - AuthException $exception): HttpResponse |
|
| 181 | + AuthException $exception): HttpResponse |
|
| 182 | 182 | { |
| 183 | 183 | $cfg = self::getExceptionHandlerConfig(); |
| 184 | 184 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @throws Ex\ArrayWithMixedKeysException |
| 209 | 209 | */ |
| 210 | 210 | protected static function error(Throwable $ex, |
| 211 | - int $api_code, int $http_code = null, string $error_message = null): HttpResponse |
|
| 211 | + int $api_code, int $http_code = null, string $error_message = null): HttpResponse |
|
| 212 | 212 | { |
| 213 | 213 | $ex_http_code = ($ex instanceof HttpException) ? $ex->getStatusCode() : $ex->getCode(); |
| 214 | 214 | $http_code = $http_code ?? $ex_http_code; |
@@ -57,11 +57,11 @@ discard block |
||
| 57 | 57 | do { |
| 58 | 58 | if ($cfg === null) { |
| 59 | 59 | // Default handler MUST be present by design and always return something useful. |
| 60 | - $cfg = self::getExceptionHandlerConfig()[ RB::KEY_DEFAULT ]; |
|
| 60 | + $cfg = self::getExceptionHandlerConfig()[RB::KEY_DEFAULT]; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $handler = new $cfg[ RB::KEY_HANDLER ](); |
|
| 64 | - $handler_result = $handler->handle($cfg[ RB::KEY_CONFIG ], $ex); |
|
| 63 | + $handler = new $cfg[RB::KEY_HANDLER](); |
|
| 64 | + $handler_result = $handler->handle($cfg[RB::KEY_CONFIG], $ex); |
|
| 65 | 65 | if ($handler_result !== null) { |
| 66 | 66 | $result = self::processException($ex, $handler_result); |
| 67 | 67 | } else { |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | $cfg = self::getExceptionHandlerConfig(); |
| 186 | 186 | |
| 187 | 187 | // This config entry is guaranted to exist. Enforced by tests. |
| 188 | - $cfg = $cfg[ HttpException::class ][ RB::KEY_CONFIG ][ HttpResponse::HTTP_UNAUTHORIZED ]; |
|
| 188 | + $cfg = $cfg[HttpException::class][RB::KEY_CONFIG][HttpResponse::HTTP_UNAUTHORIZED]; |
|
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | 191 | * NOTE: no typehint due to compatibility with Laravel signature. |
@@ -329,14 +329,14 @@ discard block |
||
| 329 | 329 | |
| 330 | 330 | // check for exact class name match... |
| 331 | 331 | if (\array_key_exists($cls, $cfg)) { |
| 332 | - $result = $cfg[ $cls ]; |
|
| 332 | + $result = $cfg[$cls]; |
|
| 333 | 333 | } else { |
| 334 | 334 | // no exact match, then lets try with `instanceof` |
| 335 | 335 | // Config entries are already sorted by priority. |
| 336 | 336 | foreach (\array_keys($cfg) as $class_name) { |
| 337 | 337 | /** @var string $class_name */ |
| 338 | 338 | if ($ex instanceof $class_name) { |
| 339 | - $result = $cfg[ $class_name ]; |
|
| 339 | + $result = $cfg[$class_name]; |
|
| 340 | 340 | break; |
| 341 | 341 | } |
| 342 | 342 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | $array = $original; |
| 41 | 41 | foreach ($merging as $m_key => $m_val) { |
| 42 | 42 | if (\array_key_exists($m_key, $original)) { |
| 43 | - $orig_type = \gettype($original[ $m_key ]); |
|
| 43 | + $orig_type = \gettype($original[$m_key]); |
|
| 44 | 44 | $m_type = \gettype($m_val); |
| 45 | 45 | if ($orig_type !== $m_type) { |
| 46 | 46 | throw new Ex\IncompatibleTypeException( |
@@ -48,12 +48,12 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | if (\is_array($m_val)) { |
| 51 | - $array[ $m_key ] = static::mergeConfig($original[ $m_key ], $m_val); |
|
| 51 | + $array[$m_key] = static::mergeConfig($original[$m_key], $m_val); |
|
| 52 | 52 | } else { |
| 53 | - $array[ $m_key ] = $m_val; |
|
| 53 | + $array[$m_key] = $m_val; |
|
| 54 | 54 | } |
| 55 | 55 | } else { |
| 56 | - $array[ $m_key ] = $m_val; |
|
| 56 | + $array[$m_key] = $m_val; |
|
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | 59 | |
@@ -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 |
@@ -98,140 +98,140 @@ discard block |
||
| 98 | 98 | * |
| 99 | 99 | * @throws Ex\MissingConfigurationKeyException |
| 100 | 100 | */ |
| 101 | - protected static function getBaseMap(): array |
|
| 102 | - { |
|
| 103 | - $tpl = 'response-builder::builder.http_%d'; |
|
| 104 | - |
|
| 105 | - return [ |
|
| 106 | - self::OK() => 'response-builder::builder.ok', |
|
| 107 | - self::NO_ERROR_MESSAGE() => 'response-builder::builder.no_error_message', |
|
| 108 | - self::EX_HTTP_EXCEPTION() => 'response-builder::builder.http_exception', |
|
| 109 | - self::EX_UNCAUGHT_EXCEPTION() => 'response-builder::builder.uncaught_exception', |
|
| 110 | - self::EX_HTTP_NOT_FOUND() => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND), |
|
| 111 | - self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE), |
|
| 112 | - self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED), |
|
| 113 | - self::EX_VALIDATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY), |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Returns API code for internal code OK |
|
| 119 | - * |
|
| 120 | - * @return int valid API code in current range |
|
| 121 | - * |
|
| 122 | - * @noinspection PhpMethodNamingConventionInspection |
|
| 123 | - * |
|
| 124 | - * @throws \InvalidArgumentException |
|
| 125 | - * @throws Ex\MissingConfigurationKeyException |
|
| 126 | - */ |
|
| 127 | - public static function OK(): int |
|
| 128 | - { |
|
| 129 | - return static::getCodeForInternalOffset(static::OK_OFFSET); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Returns API code for internal code NO_ERROR_MESSAGE |
|
| 134 | - * |
|
| 135 | - * @return int valid API code in current range |
|
| 136 | - * |
|
| 137 | - * @noinspection PhpMethodNamingConventionInspection |
|
| 138 | - * |
|
| 139 | - * @throws \InvalidArgumentException |
|
| 140 | - * @throws Ex\MissingConfigurationKeyException |
|
| 141 | - */ |
|
| 142 | - public static function NO_ERROR_MESSAGE(): int |
|
| 143 | - { |
|
| 144 | - return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Returns API code for internal code EX_HTTP_NOT_FOUND |
|
| 149 | - * |
|
| 150 | - * @return int valid API code in current range |
|
| 151 | - * |
|
| 152 | - * @noinspection PhpMethodNamingConventionInspection |
|
| 153 | - * |
|
| 154 | - * @throws \InvalidArgumentException |
|
| 155 | - * @throws Ex\MissingConfigurationKeyException |
|
| 156 | - */ |
|
| 157 | - public static function EX_HTTP_NOT_FOUND(): int |
|
| 158 | - { |
|
| 159 | - return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Returns API code for internal code EX_HTTP_EXCEPTION |
|
| 164 | - * |
|
| 165 | - * @return int valid API code in current range |
|
| 166 | - * |
|
| 167 | - * @noinspection PhpMethodNamingConventionInspection |
|
| 168 | - * |
|
| 169 | - * @throws \InvalidArgumentException |
|
| 170 | - * @throws Ex\MissingConfigurationKeyException |
|
| 171 | - */ |
|
| 172 | - public static function EX_HTTP_EXCEPTION(): int |
|
| 173 | - { |
|
| 174 | - return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Returns API code for internal code EX_UNCAUGHT_EXCEPTION |
|
| 179 | - * |
|
| 180 | - * @return int valid API code in current range |
|
| 181 | - * |
|
| 182 | - * @noinspection PhpMethodNamingConventionInspection |
|
| 183 | - * |
|
| 184 | - * @throws \InvalidArgumentException |
|
| 185 | - * @throws Ex\MissingConfigurationKeyException |
|
| 186 | - */ |
|
| 187 | - public static function EX_UNCAUGHT_EXCEPTION(): int |
|
| 188 | - { |
|
| 189 | - return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION |
|
| 194 | - * |
|
| 195 | - * @return int valid API code in current range |
|
| 196 | - * |
|
| 197 | - * @noinspection PhpMethodNamingConventionInspection |
|
| 198 | - * |
|
| 199 | - * @throws \InvalidArgumentException |
|
| 200 | - * @throws Ex\MissingConfigurationKeyException |
|
| 201 | - */ |
|
| 202 | - public static function EX_AUTHENTICATION_EXCEPTION(): int |
|
| 203 | - { |
|
| 204 | - return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Returns API code for internal code EX_VALIDATION_EXCEPTION |
|
| 209 | - * |
|
| 210 | - * @return int valid API code in current range |
|
| 211 | - * |
|
| 212 | - * @noinspection PhpMethodNamingConventionInspection |
|
| 213 | - * |
|
| 214 | - * @throws \InvalidArgumentException |
|
| 215 | - * @throws Ex\MissingConfigurationKeyException |
|
| 216 | - */ |
|
| 217 | - public static function EX_VALIDATION_EXCEPTION(): int |
|
| 218 | - { |
|
| 219 | - return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE |
|
| 224 | - * |
|
| 225 | - * @return int valid API code in current range |
|
| 226 | - * |
|
| 227 | - * @noinspection PhpMethodNamingConventionInspection |
|
| 228 | - * |
|
| 229 | - * @throws \InvalidArgumentException |
|
| 230 | - * @throws Ex\MissingConfigurationKeyException |
|
| 231 | - */ |
|
| 232 | - public static function EX_HTTP_SERVICE_UNAVAILABLE(): int |
|
| 233 | - { |
|
| 234 | - return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET); |
|
| 235 | - } |
|
| 101 | + protected static function getBaseMap(): array |
|
| 102 | + { |
|
| 103 | + $tpl = 'response-builder::builder.http_%d'; |
|
| 104 | + |
|
| 105 | + return [ |
|
| 106 | + self::OK() => 'response-builder::builder.ok', |
|
| 107 | + self::NO_ERROR_MESSAGE() => 'response-builder::builder.no_error_message', |
|
| 108 | + self::EX_HTTP_EXCEPTION() => 'response-builder::builder.http_exception', |
|
| 109 | + self::EX_UNCAUGHT_EXCEPTION() => 'response-builder::builder.uncaught_exception', |
|
| 110 | + self::EX_HTTP_NOT_FOUND() => sprintf($tpl, HttpResponse::HTTP_NOT_FOUND), |
|
| 111 | + self::EX_HTTP_SERVICE_UNAVAILABLE() => sprintf($tpl, HttpResponse::HTTP_SERVICE_UNAVAILABLE), |
|
| 112 | + self::EX_AUTHENTICATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNAUTHORIZED), |
|
| 113 | + self::EX_VALIDATION_EXCEPTION() => sprintf($tpl, HttpResponse::HTTP_UNPROCESSABLE_ENTITY), |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Returns API code for internal code OK |
|
| 119 | + * |
|
| 120 | + * @return int valid API code in current range |
|
| 121 | + * |
|
| 122 | + * @noinspection PhpMethodNamingConventionInspection |
|
| 123 | + * |
|
| 124 | + * @throws \InvalidArgumentException |
|
| 125 | + * @throws Ex\MissingConfigurationKeyException |
|
| 126 | + */ |
|
| 127 | + public static function OK(): int |
|
| 128 | + { |
|
| 129 | + return static::getCodeForInternalOffset(static::OK_OFFSET); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Returns API code for internal code NO_ERROR_MESSAGE |
|
| 134 | + * |
|
| 135 | + * @return int valid API code in current range |
|
| 136 | + * |
|
| 137 | + * @noinspection PhpMethodNamingConventionInspection |
|
| 138 | + * |
|
| 139 | + * @throws \InvalidArgumentException |
|
| 140 | + * @throws Ex\MissingConfigurationKeyException |
|
| 141 | + */ |
|
| 142 | + public static function NO_ERROR_MESSAGE(): int |
|
| 143 | + { |
|
| 144 | + return static::getCodeForInternalOffset(static::NO_ERROR_MESSAGE_OFFSET); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Returns API code for internal code EX_HTTP_NOT_FOUND |
|
| 149 | + * |
|
| 150 | + * @return int valid API code in current range |
|
| 151 | + * |
|
| 152 | + * @noinspection PhpMethodNamingConventionInspection |
|
| 153 | + * |
|
| 154 | + * @throws \InvalidArgumentException |
|
| 155 | + * @throws Ex\MissingConfigurationKeyException |
|
| 156 | + */ |
|
| 157 | + public static function EX_HTTP_NOT_FOUND(): int |
|
| 158 | + { |
|
| 159 | + return static::getCodeForInternalOffset(static::EX_HTTP_NOT_FOUND_OFFSET); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Returns API code for internal code EX_HTTP_EXCEPTION |
|
| 164 | + * |
|
| 165 | + * @return int valid API code in current range |
|
| 166 | + * |
|
| 167 | + * @noinspection PhpMethodNamingConventionInspection |
|
| 168 | + * |
|
| 169 | + * @throws \InvalidArgumentException |
|
| 170 | + * @throws Ex\MissingConfigurationKeyException |
|
| 171 | + */ |
|
| 172 | + public static function EX_HTTP_EXCEPTION(): int |
|
| 173 | + { |
|
| 174 | + return static::getCodeForInternalOffset(static::EX_HTTP_EXCEPTION_OFFSET); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Returns API code for internal code EX_UNCAUGHT_EXCEPTION |
|
| 179 | + * |
|
| 180 | + * @return int valid API code in current range |
|
| 181 | + * |
|
| 182 | + * @noinspection PhpMethodNamingConventionInspection |
|
| 183 | + * |
|
| 184 | + * @throws \InvalidArgumentException |
|
| 185 | + * @throws Ex\MissingConfigurationKeyException |
|
| 186 | + */ |
|
| 187 | + public static function EX_UNCAUGHT_EXCEPTION(): int |
|
| 188 | + { |
|
| 189 | + return static::getCodeForInternalOffset(static::EX_UNCAUGHT_EXCEPTION_OFFSET); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Returns API code for internal code EX_AUTHENTICATION_EXCEPTION |
|
| 194 | + * |
|
| 195 | + * @return int valid API code in current range |
|
| 196 | + * |
|
| 197 | + * @noinspection PhpMethodNamingConventionInspection |
|
| 198 | + * |
|
| 199 | + * @throws \InvalidArgumentException |
|
| 200 | + * @throws Ex\MissingConfigurationKeyException |
|
| 201 | + */ |
|
| 202 | + public static function EX_AUTHENTICATION_EXCEPTION(): int |
|
| 203 | + { |
|
| 204 | + return static::getCodeForInternalOffset(static::EX_AUTHENTICATION_EXCEPTION_OFFSET); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Returns API code for internal code EX_VALIDATION_EXCEPTION |
|
| 209 | + * |
|
| 210 | + * @return int valid API code in current range |
|
| 211 | + * |
|
| 212 | + * @noinspection PhpMethodNamingConventionInspection |
|
| 213 | + * |
|
| 214 | + * @throws \InvalidArgumentException |
|
| 215 | + * @throws Ex\MissingConfigurationKeyException |
|
| 216 | + */ |
|
| 217 | + public static function EX_VALIDATION_EXCEPTION(): int |
|
| 218 | + { |
|
| 219 | + return static::getCodeForInternalOffset(static::EX_VALIDATION_EXCEPTION_OFFSET); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Returns API code for internal code EX_HTTP_SERVICE_UNAVAILABLE |
|
| 224 | + * |
|
| 225 | + * @return int valid API code in current range |
|
| 226 | + * |
|
| 227 | + * @noinspection PhpMethodNamingConventionInspection |
|
| 228 | + * |
|
| 229 | + * @throws \InvalidArgumentException |
|
| 230 | + * @throws Ex\MissingConfigurationKeyException |
|
| 231 | + */ |
|
| 232 | + public static function EX_HTTP_SERVICE_UNAVAILABLE(): int |
|
| 233 | + { |
|
| 234 | + return static::getCodeForInternalOffset(static::EX_HTTP_SERVICE_UNAVAILABLE_OFFSET); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | 237 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | protected function getPrimitiveMappingConfigOrThrow($data): array |
| 63 | 63 | { |
| 64 | 64 | $type = \gettype($data); |
| 65 | - $result = $this->primitives[ $type ] ?? null; |
|
| 65 | + $result = $this->primitives[$type] ?? null; |
|
| 66 | 66 | |
| 67 | 67 | if ($result === null) { |
| 68 | 68 | throw new Ex\ConfigurationNotFoundException( |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | $cls = \get_class($data); |
| 95 | 95 | if (\is_string($cls)) { |
| 96 | 96 | if (\array_key_exists($cls, $this->classes)) { |
| 97 | - $result = $this->classes[ $cls ]; |
|
| 97 | + $result = $this->classes[$cls]; |
|
| 98 | 98 | $debug_result = 'exact config match'; |
| 99 | 99 | } else { |
| 100 | 100 | // no exact match, then lets try with `instanceof` |
| 101 | 101 | foreach (\array_keys($this->classes) as $class_name) { |
| 102 | 102 | /** @var string $class_name */ |
| 103 | 103 | if ($data instanceof $class_name) { |
| 104 | - $result = $this->classes[ $class_name ]; |
|
| 104 | + $result = $this->classes[$class_name]; |
|
| 105 | 105 | $debug_result = "subclass of {$class_name}"; |
| 106 | 106 | break; |
| 107 | 107 | } |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | if ($result === null && \is_object($data)) { |
| 152 | 152 | $cfg = $this->getClassMappingConfigOrThrow($data); |
| 153 | - $worker = new $cfg[ RB::KEY_HANDLER ](); |
|
| 153 | + $worker = new $cfg[RB::KEY_HANDLER](); |
|
| 154 | 154 | $result = $worker->convert($data, $cfg); |
| 155 | - $result = $cfg[ RB::KEY_KEY ] === null ? $result : [$cfg[ RB::KEY_KEY ] => $result]; |
|
| 155 | + $result = $cfg[RB::KEY_KEY] === null ? $result : [$cfg[RB::KEY_KEY] => $result]; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | if ($result === null && \is_array($data)) { |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | $result = $this->convertArray($data); |
| 162 | 162 | if (!Util::isArrayWithNonNumericKeys($data)) { |
| 163 | - $result = [$cfg[ RB::KEY_KEY ] => $result]; |
|
| 163 | + $result = [$cfg[RB::KEY_KEY] => $result]; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | if (\is_bool($data) || \is_float($data) || \is_int($data) || \is_string($data)) { |
| 168 | - $result = [$this->getPrimitiveMappingConfigOrThrow($data)[ RB::KEY_KEY ] => $data]; |
|
| 168 | + $result = [$this->getPrimitiveMappingConfigOrThrow($data)[RB::KEY_KEY] => $data]; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | return $result; |
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | foreach ($data as $key => $val) { |
| 190 | 190 | if (\is_array($val)) { |
| 191 | - $data[ $key ] = $this->convertArray($val); |
|
| 191 | + $data[$key] = $this->convertArray($val); |
|
| 192 | 192 | } elseif (\is_object($val)) { |
| 193 | 193 | $cfg = $this->getClassMappingConfigOrThrow($val); |
| 194 | - $worker = new $cfg[ RB::KEY_HANDLER ](); |
|
| 194 | + $worker = new $cfg[RB::KEY_HANDLER](); |
|
| 195 | 195 | $converted_data = $worker->convert($val, $cfg); |
| 196 | - $data[ $key ] = $converted_data; |
|
| 196 | + $data[$key] = $converted_data; |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
@@ -43,6 +43,6 @@ |
||
| 43 | 43 | $encoded = ''; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return [$config[ RB::KEY_KEY ] => \json_decode($encoded, true)]; |
|
| 46 | + return [$config[RB::KEY_KEY] => \json_decode($encoded, true)]; |
|
| 47 | 47 | } |
| 48 | 48 | } |
@@ -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; |