8000 [Bugfix] Correct type-hinting in error response methods · nelson6e65/laravel-json-api@744d4e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 744d4e0

Browse files
committed
[Bugfix] Correct type-hinting in error response methods
1 parent 6199da9 commit 744d4e0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file. This projec
1010
### Fixed
1111
- [#506](https://github.com/cloudcreativity/laravel-json-api/pull/506)
1212
Resolve model bindings correctly when substituting URL parameters.
13+
- Updated type-hinting for `Responses::errros()` method and allowed a `null` default
14+
status code to be passed to `Helpers::httpErrorStatus()` method.
1315

1416
## [2.0.0-beta.3] - 2020-04-13
1517

src/Http/Responses/Responses.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public function error($error, int $defaultStatusCode = null, array $headers = []
413413
* @param array $headers
414414
* @return mixed
415415
*/
416-
public function errors(iterable $errors, $defaultStatusCode = null, array $headers = [])
416+
public function errors(iterable $errors, int $defaultStatusCode = null, array $headers = [])
417417
{
418418
$errors = $this->factory->createErrors($errors);
419419
$statusCode = Helpers::httpErrorStatus($errors, $defaultStatusCode);

src/Utils/Helpers.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,17 @@ public static function isJsonApi($request)
157157
* 4xx errors or 500 Internal Server Error might be appropriate for multiple 5xx errors.
158158
*
159159
* @param iterable|ErrorInterface $errors
160-
* @param int $default
160+
* @param int|null $default
161161
* @return int
162162
* @see https://jsonapi.org/format/#errors
163163
* @deprecated 3.0.0 use `Document\Error\Errors::getStatus()`
164164
*/
165-
public static function httpErrorStatus($errors, int $default = SymfonyResponse::HTTP_BAD_REQUEST): int
165+
public static function httpErrorStatus($errors, int $default = null): int
166166
{
167+
if (\is_null($default)) {
168+
$default = SymfonyResponse::HTTP_BAD_REQUEST;
169+
}
170+
167171
if ($errors instanceof ErrorInterface) {
168172
$errors = [$errors];
169173
}

0 commit comments

Comments
 (0)
0