@@ -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'; |
@@ -92,7 +92,7 @@ |
||
92 | 92 | if (is_numeric($key)) { |
93 | 93 | continue; |
94 | 94 | } |
95 | - $array[ $key ] = $this->mergeConfig($value, $merging[ $key ]); |
|
95 | + $array[$key] = $this->mergeConfig($value, $merging[$key]); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | return $array; |
@@ -112,7 +112,7 @@ |
||
112 | 112 | |
113 | 113 | $map = static::getMap(); |
114 | 114 | |
115 | - return $map[ $api_code ] ?? null; |
|
115 | + return $map[$api_code] ?? null; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | public static function isCodeValid($code): bool |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @return HttpResponse |
137 | 137 | */ |
138 | 138 | public static function success($data = null, $api_code = null, array $lang_args = null, |
139 | - int $http_code = null, int $encoding_options = null): HttpResponse |
|
139 | + int $http_code = null, int $encoding_options = null): HttpResponse |
|
140 | 140 | { |
141 | 141 | return static::buildSuccessResponse($data, $api_code, $lang_args, $http_code, $encoding_options); |
142 | 142 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * @throws \InvalidArgumentException Thrown when provided arguments are invalid. |
182 | 182 | */ |
183 | 183 | protected static function buildSuccessResponse($data = null, int $api_code = null, array $lang_args = null, |
184 | - int $http_code = null, int $encoding_options = null): HttpResponse |
|
184 | + int $http_code = null, int $encoding_options = null): HttpResponse |
|
185 | 185 | { |
186 | 186 | $http_code = $http_code ?? static::DEFAULT_HTTP_CODE_OK; |
187 | 187 | $api_code = $api_code ?? BaseApiCodes::OK(); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @return HttpResponse |
208 | 208 | */ |
209 | 209 | public static function error(int $api_code, array $lang_args = null, $data = null, int $http_code = null, |
210 | - int $encoding_options = null): HttpResponse |
|
210 | + int $encoding_options = null): HttpResponse |
|
211 | 211 | { |
212 | 212 | return static::buildErrorResponse($data, $api_code, $http_code, $lang_args, $encoding_options); |
213 | 213 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @return HttpResponse |
223 | 223 | */ |
224 | 224 | public static function errorWithData(int $api_code, $data, array $lang_args = null, |
225 | - int $encoding_options = null): HttpResponse |
|
225 | + int $encoding_options = null): HttpResponse |
|
226 | 226 | { |
227 | 227 | return static::buildErrorResponse($data, $api_code, null, $lang_args, $encoding_options); |
228 | 228 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @throws \InvalidArgumentException if http_code is @null |
241 | 241 | */ |
242 | 242 | public static function errorWithDataAndHttpCode(int $api_code, $data, int $http_code, array $lang_args = null, |
243 | - int $encoding_options = null): HttpResponse |
|
243 | + int $encoding_options = null): HttpResponse |
|
244 | 244 | { |
245 | 245 | return static::buildErrorResponse($data, $api_code, $http_code, $lang_args, $encoding_options); |
246 | 246 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @return HttpResponse |
271 | 271 | */ |
272 | 272 | public static function errorWithMessageAndData(int $api_code, string $error_message, $data, |
273 | - int $http_code = null, int $encoding_options = null): HttpResponse |
|
273 | + int $http_code = null, int $encoding_options = null): HttpResponse |
|
274 | 274 | { |
275 | 275 | return static::buildErrorResponse($data, $api_code, $http_code, null, |
276 | 276 | $error_message, null, $encoding_options); |
@@ -288,8 +288,8 @@ discard block |
||
288 | 288 | * @return HttpResponse |
289 | 289 | */ |
290 | 290 | public static function errorWithMessageAndDataAndDebug(int $api_code, string $error_message, $data, |
291 | - int $http_code = null, int $encoding_options = null, |
|
292 | - array $debug_data = null): HttpResponse |
|
291 | + int $http_code = null, int $encoding_options = null, |
|
292 | + array $debug_data = null): HttpResponse |
|
293 | 293 | { |
294 | 294 | return static::buildErrorResponse($data, $api_code, $http_code, null, |
295 | 295 | $error_message, null, $encoding_options, $debug_data); |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | * @noinspection MoreThanThreeArgumentsInspection |
329 | 329 | */ |
330 | 330 | protected static function buildErrorResponse($data, int $api_code, int $http_code = null, array $lang_args = null, |
331 | - string $message = null, array $headers = null, int $encoding_options = null, |
|
332 | - array $debug_data = null): HttpResponse |
|
331 | + string $message = null, array $headers = null, int $encoding_options = null, |
|
332 | + array $debug_data = null): HttpResponse |
|
333 | 333 | { |
334 | 334 | $http_code = $http_code ?? static::DEFAULT_HTTP_CODE_ERROR; |
335 | 335 | $headers = $headers ?? []; |
@@ -372,8 +372,8 @@ discard block |
||
372 | 372 | * @noinspection MoreThanThreeArgumentsInspection |
373 | 373 | */ |
374 | 374 | protected static function make(bool $success, int $api_code, $message_or_api_code, $data = null, |
375 | - int $http_code = null, array $lang_args = null, array $headers = null, |
|
376 | - int $encoding_options = null, array $debug_data = null): HttpResponse |
|
375 | + int $http_code = null, array $lang_args = null, array $headers = null, |
|
376 | + int $encoding_options = null, array $debug_data = null): HttpResponse |
|
377 | 377 | { |
378 | 378 | $headers = $headers ?? []; |
379 | 379 | $http_code = $http_code ?? ($success ? static::DEFAULT_HTTP_CODE_OK : static::DEFAULT_HTTP_CODE_ERROR); |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | * @throws \RuntimeException in case of missing or invalid "classes" mapping configuration |
430 | 430 | */ |
431 | 431 | protected static function buildResponse(bool $success, int $api_code, string $message, $data = null, |
432 | - array $debug_data = null): array |
|
432 | + array $debug_data = null): array |
|
433 | 433 | { |
434 | 434 | // ensure $data is either @null, array or object of class with configured mapping. |
435 | 435 | $converter = new Converter(); |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | $data = $converter->convert($data); |
438 | 438 | if ($data !== null && !is_object($data)) { |
439 | 439 | // ensure we get object in final JSON structure in data node |
440 | - $data = (object)$data; |
|
440 | + $data = (object) $data; |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** @noinspection PhpUndefinedClassInspection */ |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | |
452 | 452 | if ($debug_data !== null) { |
453 | 453 | $debug_key = Config::get(static::CONF_KEY_DEBUG_DEBUG_KEY, self::KEY_DEBUG); |
454 | - $response[ $debug_key ] = $debug_data; |
|
454 | + $response[$debug_key] = $debug_data; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | return $response; |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | // check for exact class name match... |
70 | 70 | $cls = get_class($data); |
71 | 71 | if (array_key_exists($cls, $this->classes)) { |
72 | - $result = $this->classes[ $cls ]; |
|
72 | + $result = $this->classes[$cls]; |
|
73 | 73 | } else { |
74 | 74 | // no exact match, then lets try with `instanceof` |
75 | 75 | foreach (array_keys($this->classes) as $class_name) { |
76 | 76 | if ($data instanceof $class_name) { |
77 | - $result = $this->classes[ $class_name ]; |
|
77 | + $result = $this->classes[$class_name]; |
|
78 | 78 | break; |
79 | 79 | } |
80 | 80 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | if (is_object($data)) { |
104 | 104 | $cfg = $this->getClassMappingConfigOrThrow($data); |
105 | - $data = [$cfg[ ResponseBuilder::KEY_KEY ] => $data->{$cfg[ ResponseBuilder::KEY_METHOD ]}()]; |
|
105 | + $data = [$cfg[ResponseBuilder::KEY_KEY] => $data->{$cfg[ResponseBuilder::KEY_METHOD]}()]; |
|
106 | 106 | } elseif (!is_array($data)) { |
107 | 107 | throw new \InvalidArgumentException( |
108 | 108 | sprintf('Invalid payload data. Must be null, array or object with mapping ("%s" given).', gettype($data))); |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | |
143 | 143 | foreach ($data as $key => $val) { |
144 | 144 | if (is_array($val)) { |
145 | - $data[ $key ] = $this->convertArray($val); |
|
145 | + $data[$key] = $this->convertArray($val); |
|
146 | 146 | } elseif (is_object($val)) { |
147 | 147 | $cls = get_class($val); |
148 | 148 | if (array_key_exists($cls, $this->classes)) { |
149 | - $conversion_method = $this->classes[ $cls ][ ResponseBuilder::KEY_METHOD ]; |
|
149 | + $conversion_method = $this->classes[$cls][ResponseBuilder::KEY_METHOD]; |
|
150 | 150 | $converted_data = $val->$conversion_method(); |
151 | - $data[ $key ] = $converted_data; |
|
151 | + $data[$key] = $converted_data; |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | } |