@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @return HttpResponse |
142 | 142 | */ |
143 | 143 | public static function success($data = null, $api_code = null, array $placeholders = null, |
144 | - int $http_code = null, int $encoding_opts = null): HttpResponse |
|
144 | + int $http_code = null, int $encoding_opts = null): HttpResponse |
|
145 | 145 | { |
146 | 146 | return static::buildSuccessResponse($data, $api_code, $placeholders, $http_code, $encoding_opts); |
147 | 147 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return HttpResponse |
159 | 159 | */ |
160 | 160 | public static function successWithCode(int $api_code = null, array $placeholders = null, |
161 | - int $http_code = null): HttpResponse |
|
161 | + int $http_code = null): HttpResponse |
|
162 | 162 | { |
163 | 163 | return static::success(null, $api_code, $placeholders, $http_code); |
164 | 164 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @throws \InvalidArgumentException Thrown when provided arguments are invalid. |
194 | 194 | */ |
195 | 195 | protected static function buildSuccessResponse($data = null, int $api_code = null, array $placeholders = null, |
196 | - int $http_code = null, int $encoding_opts = null): HttpResponse |
|
196 | + int $http_code = null, int $encoding_opts = null): HttpResponse |
|
197 | 197 | { |
198 | 198 | $http_code = $http_code ?? static::DEFAULT_HTTP_CODE_OK; |
199 | 199 | $api_code = $api_code ?? BaseApiCodes::OK(); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * @return HttpResponse |
224 | 224 | */ |
225 | 225 | public static function error(int $api_code, array $placeholders = null, $data = null, int $http_code = null, |
226 | - int $encoding_options = null): HttpResponse |
|
226 | + int $encoding_options = null): HttpResponse |
|
227 | 227 | { |
228 | 228 | return static::buildErrorResponse($data, $api_code, $http_code, $placeholders, $encoding_options); |
229 | 229 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @return HttpResponse |
242 | 242 | */ |
243 | 243 | public static function errorWithData(int $api_code, $data, array $placeholders = null, |
244 | - int $encoding_opts = null): HttpResponse |
|
244 | + int $encoding_opts = null): HttpResponse |
|
245 | 245 | { |
246 | 246 | return static::buildErrorResponse($data, $api_code, null, $placeholders, $encoding_opts); |
247 | 247 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @throws \InvalidArgumentException if http_code is @null |
263 | 263 | */ |
264 | 264 | public static function errorWithDataAndHttpCode(int $api_code, $data, int $http_code, array $placeholders = null, |
265 | - int $encoding_opts = null): HttpResponse |
|
265 | + int $encoding_opts = null): HttpResponse |
|
266 | 266 | { |
267 | 267 | return static::buildErrorResponse($data, $api_code, $http_code, $placeholders, $encoding_opts); |
268 | 268 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * @return HttpResponse |
297 | 297 | */ |
298 | 298 | public static function errorWithMessageAndData(int $api_code, string $message, $data, |
299 | - int $http_code = null, int $encoding_opts = null): HttpResponse |
|
299 | + int $http_code = null, int $encoding_opts = null): HttpResponse |
|
300 | 300 | { |
301 | 301 | return static::buildErrorResponse($data, $api_code, $http_code, null, |
302 | 302 | $message, null, $encoding_opts); |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | * @return HttpResponse |
318 | 318 | */ |
319 | 319 | public static function errorWithMessageAndDataAndDebug(int $api_code, string $message, $data, |
320 | - int $http_code = null, int $encoding_opts = null, |
|
321 | - array $debug_data = null): HttpResponse |
|
320 | + int $http_code = null, int $encoding_opts = null, |
|
321 | + array $debug_data = null): HttpResponse |
|
322 | 322 | { |
323 | 323 | return static::buildErrorResponse($data, $api_code, $http_code, null, |
324 | 324 | $message, null, $encoding_opts, $debug_data); |
@@ -362,10 +362,10 @@ discard block |
||
362 | 362 | * @noinspection MoreThanThreeArgumentsInspection |
363 | 363 | */ |
364 | 364 | protected static function buildErrorResponse($data, int $api_code, int $http_code = null, |
365 | - array $placeholders = null, |
|
366 | - string $message = null, array $headers = null, |
|
367 | - int $encoding_opts = null, |
|
368 | - array $debug_data = null): HttpResponse |
|
365 | + array $placeholders = null, |
|
366 | + string $message = null, array $headers = null, |
|
367 | + int $encoding_opts = null, |
|
368 | + array $debug_data = null): HttpResponse |
|
369 | 369 | { |
370 | 370 | $http_code = $http_code ?? static::DEFAULT_HTTP_CODE_ERROR; |
371 | 371 | $headers = $headers ?? []; |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | * @noinspection MoreThanThreeArgumentsInspection |
413 | 413 | */ |
414 | 414 | protected static function make(bool $success, int $api_code, $msg_or_api_code, $data = null, |
415 | - int $http_code = null, array $placeholders = null, array $headers = null, |
|
416 | - int $encoding_opts = null, array $debug_data = null): HttpResponse |
|
415 | + int $http_code = null, array $placeholders = null, array $headers = null, |
|
416 | + int $encoding_opts = null, array $debug_data = null): HttpResponse |
|
417 | 417 | { |
418 | 418 | $headers = $headers ?? []; |
419 | 419 | $http_code = $http_code ?? ($success ? static::DEFAULT_HTTP_CODE_OK : static::DEFAULT_HTTP_CODE_ERROR); |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | * @throws \RuntimeException in case of missing or invalid "classes" mapping configuration |
482 | 482 | */ |
483 | 483 | protected static function buildResponse(bool $success, int $api_code, |
484 | - $msg_or_api_code, array $placeholders = null, |
|
485 | - $data = null, array $debug_data = null): array |
|
484 | + $msg_or_api_code, array $placeholders = null, |
|
485 | + $data = null, array $debug_data = null): array |
|
486 | 486 | { |
487 | 487 | // ensure $data is either @null, array or object of class with configured mapping. |
488 | 488 | $converter = new Converter(); |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | $data = $converter->convert($data); |
491 | 491 | if ($data !== null && !is_object($data)) { |
492 | 492 | // ensure we get object in final JSON structure in data node |
493 | - $data = (object)$data; |
|
493 | + $data = (object) $data; |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | $placeholders = $placeholders ?? []; |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | |
515 | 515 | if ($debug_data !== null) { |
516 | 516 | $debug_key = Config::get(static::CONF_KEY_DEBUG_DEBUG_KEY, self::KEY_DEBUG); |
517 | - $response[ $debug_key ] = $debug_data; |
|
517 | + $response[$debug_key] = $debug_data; |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | return $response; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return HttpResponse |
95 | 95 | */ |
96 | 96 | protected function unauthenticated(/** @scrutinizer ignore-unused */ $request, |
97 | - AuthenticationException $exception): HttpResponse |
|
97 | + AuthenticationException $exception): HttpResponse |
|
98 | 98 | { |
99 | 99 | return static::error($exception, 'authentication_exception', BaseApiCodes::EX_AUTHENTICATION_EXCEPTION()); |
100 | 100 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @return HttpResponse |
111 | 111 | */ |
112 | 112 | protected static function error(Exception $exception, $exception_config_key, $fallback_api_code, |
113 | - $fallback_http_code = ResponseBuilder::DEFAULT_HTTP_CODE_ERROR): HttpResponse |
|
113 | + $fallback_http_code = ResponseBuilder::DEFAULT_HTTP_CODE_ERROR): HttpResponse |
|
114 | 114 | { |
115 | 115 | // common prefix for config key |
116 | 116 | $base_key = sprintf('%s.exception', ResponseBuilder::CONF_EXCEPTION_HANDLER_KEY); |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | // check for exact class name match... |
73 | 73 | $cls = get_class($data); |
74 | 74 | if (array_key_exists($cls, $this->classes)) { |
75 | - $result = $this->classes[ $cls ]; |
|
75 | + $result = $this->classes[$cls]; |
|
76 | 76 | } else { |
77 | 77 | // no exact match, then lets try with `instanceof` |
78 | 78 | foreach (array_keys($this->classes) as $class_name) { |
79 | 79 | if ($data instanceof $class_name) { |
80 | - $result = $this->classes[ $class_name ]; |
|
80 | + $result = $this->classes[$class_name]; |
|
81 | 81 | break; |
82 | 82 | } |
83 | 83 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | if (is_object($data)) { |
109 | 109 | $cfg = $this->getClassMappingConfigOrThrow($data); |
110 | - $data = [$cfg[ ResponseBuilder::KEY_KEY ] => $data->{$cfg[ ResponseBuilder::KEY_METHOD ]}()]; |
|
110 | + $data = [$cfg[ResponseBuilder::KEY_KEY] => $data->{$cfg[ResponseBuilder::KEY_METHOD]}()]; |
|
111 | 111 | } elseif (!is_array($data)) { |
112 | 112 | throw new \InvalidArgumentException( |
113 | 113 | sprintf('Payload must be null, array or object with mapping ("%s" given).', gettype($data))); |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | |
150 | 150 | foreach ($data as $key => $val) { |
151 | 151 | if (is_array($val)) { |
152 | - $data[ $key ] = $this->convertArray($val); |
|
152 | + $data[$key] = $this->convertArray($val); |
|
153 | 153 | } elseif (is_object($val)) { |
154 | 154 | $cls = get_class($val); |
155 | 155 | if (array_key_exists($cls, $this->classes)) { |
156 | - $conversion_method = $this->classes[ $cls ][ ResponseBuilder::KEY_METHOD ]; |
|
156 | + $conversion_method = $this->classes[$cls][ResponseBuilder::KEY_METHOD]; |
|
157 | 157 | $converted_data = $val->$conversion_method(); |
158 | - $data[ $key ] = $converted_data; |
|
158 | + $data[$key] = $converted_data; |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |