@@ -107,7 +107,7 @@ |
||
| 107 | 107 | * @return HttpResponse |
| 108 | 108 | */ |
| 109 | 109 | protected static function error(Exception $exception, $exception_type, $default_api_code, |
| 110 | - $default_http_code = ResponseBuilder::DEFAULT_HTTP_CODE_ERROR): HttpResponse |
|
| 110 | + $default_http_code = ResponseBuilder::DEFAULT_HTTP_CODE_ERROR): HttpResponse |
|
| 111 | 111 | { |
| 112 | 112 | // common prefix for config key |
| 113 | 113 | $base_config = 'response_builder.exception_handler.exception'; |
@@ -149,7 +149,7 @@ |
||
| 149 | 149 | $data = null; |
| 150 | 150 | if ($api_code === Config::get("{$base_config}.validation_exception.code", BaseApiCodes::EX_VALIDATION_EXCEPTION())) { |
| 151 | 151 | /** @var ValidationException $exception */ |
| 152 | - $data = [ResponseBuilder::KEY_MESSAGES => $exception->validator->errors()->messages()]; |
|
| 152 | + $data = [ ResponseBuilder::KEY_MESSAGES => $exception->validator->errors()->messages() ]; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | $key = BaseApiCodes::getCodeMessageKey($api_code) ?? BaseApiCodes::getCodeMessageKey($base_api_code); |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | public function register() |
| 34 | 34 | { |
| 35 | 35 | $this->mergeConfigFrom( |
| 36 | - __DIR__.'/../config/response_builder.php', 'response_builder' |
|
| 36 | + __DIR__ . '/../config/response_builder.php', 'response_builder' |
|
| 37 | 37 | ); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @return HttpResponse |
| 185 | 185 | */ |
| 186 | 186 | public static function success($data = null, $api_code = null, array $lang_args = null, |
| 187 | - int $http_code = null, int $encoding_options = null): HttpResponse |
|
| 187 | + int $http_code = null, int $encoding_options = null): HttpResponse |
|
| 188 | 188 | { |
| 189 | 189 | return static::buildSuccessResponse($data, $api_code, $lang_args, $http_code, $encoding_options); |
| 190 | 190 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * @throws \InvalidArgumentException Thrown when provided arguments are invalid. |
| 230 | 230 | */ |
| 231 | 231 | protected static function buildSuccessResponse($data = null, int $api_code = null, array $lang_args = null, |
| 232 | - int $http_code = null, int $encoding_options = null): HttpResponse |
|
| 232 | + int $http_code = null, int $encoding_options = null): HttpResponse |
|
| 233 | 233 | { |
| 234 | 234 | $http_code = $http_code ?? static::DEFAULT_HTTP_CODE_OK; |
| 235 | 235 | $api_code = $api_code ?? BaseApiCodes::OK(); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | * @return HttpResponse |
| 256 | 256 | */ |
| 257 | 257 | public static function error(int $api_code, array $lang_args = null, $data = null, int $http_code = null, |
| 258 | - int $encoding_options = null): HttpResponse |
|
| 258 | + int $encoding_options = null): HttpResponse |
|
| 259 | 259 | { |
| 260 | 260 | return static::buildErrorResponse($data, $api_code, $http_code, $lang_args, $encoding_options); |
| 261 | 261 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @return HttpResponse |
| 271 | 271 | */ |
| 272 | 272 | public static function errorWithData(int $api_code, $data, array $lang_args = null, |
| 273 | - int $encoding_options = null): HttpResponse |
|
| 273 | + int $encoding_options = null): HttpResponse |
|
| 274 | 274 | { |
| 275 | 275 | return static::buildErrorResponse($data, $api_code, null, $lang_args, $encoding_options); |
| 276 | 276 | } |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @throws \InvalidArgumentException if http_code is @null |
| 289 | 289 | */ |
| 290 | 290 | public static function errorWithDataAndHttpCode(int $api_code, $data, int $http_code, array $lang_args = null, |
| 291 | - int $encoding_options = null): HttpResponse |
|
| 291 | + int $encoding_options = null): HttpResponse |
|
| 292 | 292 | { |
| 293 | 293 | return static::buildErrorResponse($data, $api_code, $http_code, $lang_args, $encoding_options); |
| 294 | 294 | } |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @return HttpResponse |
| 319 | 319 | */ |
| 320 | 320 | public static function errorWithMessageAndData(int $api_code, string $error_message, $data, |
| 321 | - int $http_code = null, int $encoding_options = null): HttpResponse |
|
| 321 | + int $http_code = null, int $encoding_options = null): HttpResponse |
|
| 322 | 322 | { |
| 323 | 323 | return static::buildErrorResponse($data, $api_code, $http_code, null, |
| 324 | 324 | $error_message, null, $encoding_options); |
@@ -336,8 +336,8 @@ discard block |
||
| 336 | 336 | * @return HttpResponse |
| 337 | 337 | */ |
| 338 | 338 | public static function errorWithMessageAndDataAndDebug(int $api_code, string $error_message, $data, |
| 339 | - int $http_code = null, int $encoding_options = null, |
|
| 340 | - array $debug_data = null): HttpResponse |
|
| 339 | + int $http_code = null, int $encoding_options = null, |
|
| 340 | + array $debug_data = null): HttpResponse |
|
| 341 | 341 | { |
| 342 | 342 | return static::buildErrorResponse($data, $api_code, $http_code, null, |
| 343 | 343 | $error_message, null, $encoding_options, $debug_data); |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | * @noinspection MoreThanThreeArgumentsInspection |
| 377 | 377 | */ |
| 378 | 378 | protected static function buildErrorResponse($data, int $api_code, int $http_code = null, array $lang_args = null, |
| 379 | - string $message = null, array $headers = null, int $encoding_options = null, |
|
| 380 | - array $debug_data = null): HttpResponse |
|
| 379 | + string $message = null, array $headers = null, int $encoding_options = null, |
|
| 380 | + array $debug_data = null): HttpResponse |
|
| 381 | 381 | { |
| 382 | 382 | $http_code = $http_code ?? static::DEFAULT_HTTP_CODE_ERROR; |
| 383 | 383 | $headers = $headers ?? []; |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | * @noinspection MoreThanThreeArgumentsInspection |
| 421 | 421 | */ |
| 422 | 422 | protected static function make(bool $success, int $api_code, $message_or_api_code, $data = null, |
| 423 | - int $http_code = null, array $lang_args = null, array $headers = null, |
|
| 424 | - int $encoding_options = null, array $debug_data = null): HttpResponse |
|
| 423 | + int $http_code = null, array $lang_args = null, array $headers = null, |
|
| 424 | + int $encoding_options = null, array $debug_data = null): HttpResponse |
|
| 425 | 425 | { |
| 426 | 426 | $headers = $headers ?? []; |
| 427 | 427 | $http_code = $http_code ?? ($success ? static::DEFAULT_HTTP_CODE_OK : static::DEFAULT_HTTP_CODE_ERROR); |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | * @throws \RuntimeException in case of missing or invalid "classes" mapping configuration |
| 478 | 478 | */ |
| 479 | 479 | protected static function buildResponse(bool $success, int $api_code, string $message, $data = null, |
| 480 | - array $debug_data = null): array |
|
| 480 | + array $debug_data = null): array |
|
| 481 | 481 | { |
| 482 | 482 | // ensure $data is either @null, array or object of class with configured mapping. |
| 483 | 483 | if ($data !== null) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | } else { |
| 120 | - $classes = []; |
|
| 120 | + $classes = [ ]; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return $classes; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | public static function successWithHttpCode(int $http_code = null): HttpResponse |
| 215 | 215 | { |
| 216 | - return static::buildSuccessResponse(null, BaseApiCodes::OK(), [], $http_code); |
|
| 216 | + return static::buildSuccessResponse(null, BaseApiCodes::OK(), [ ], $http_code); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | array $debug_data = null): HttpResponse |
| 381 | 381 | { |
| 382 | 382 | $http_code = $http_code ?? static::DEFAULT_HTTP_CODE_ERROR; |
| 383 | - $headers = $headers ?? []; |
|
| 383 | + $headers = $headers ?? [ ]; |
|
| 384 | 384 | |
| 385 | 385 | $code_ok = BaseApiCodes::OK(); |
| 386 | 386 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | int $http_code = null, array $lang_args = null, array $headers = null, |
| 424 | 424 | int $encoding_options = null, array $debug_data = null): HttpResponse |
| 425 | 425 | { |
| 426 | - $headers = $headers ?? []; |
|
| 426 | + $headers = $headers ?? [ ]; |
|
| 427 | 427 | $http_code = $http_code ?? ($success ? static::DEFAULT_HTTP_CODE_OK : static::DEFAULT_HTTP_CODE_ERROR); |
| 428 | 428 | $encoding_options = $encoding_options ?? Config::get(self::CONF_KEY_ENCODING_OPTIONS, static::DEFAULT_ENCODING_OPTIONS); |
| 429 | 429 | |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | $key = BaseApiCodes::getCodeMessageKey($success ? BaseApiCodes::OK() : BaseApiCodes::NO_ERROR_MESSAGE()); |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - $lang_args = $lang_args ?? ['api_code' => $message_or_api_code]; |
|
| 455 | + $lang_args = $lang_args ?? [ 'api_code' => $message_or_api_code ]; |
|
| 456 | 456 | $message_or_api_code = \Lang::get($key, $lang_args); |
| 457 | 457 | } |
| 458 | 458 | |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | $obj_class_name = get_class($data); |
| 502 | 502 | if (array_key_exists($obj_class_name, $classes)) { |
| 503 | 503 | $conversion_method = $classes[ $obj_class_name ][ static::KEY_METHOD ]; |
| 504 | - $data = [$classes[ $obj_class_name ][ static::KEY_KEY ] => $data->$conversion_method()]; |
|
| 504 | + $data = [ $classes[ $obj_class_name ][ static::KEY_KEY ] => $data->$conversion_method() ]; |
|
| 505 | 505 | } |
| 506 | 506 | } |
| 507 | 507 | } |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | |
| 510 | 510 | if ($data !== null && !is_object($data)) { |
| 511 | 511 | // ensure we get object in final JSON structure in data node |
| 512 | - $data = (object)$data; |
|
| 512 | + $data = (object) $data; |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | $response = [ |