Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Http\Client\Request data-method has incomplete return type or returns wrong value #47727

Closed
renky opened this issue Jul 12, 2023 · 1 comment
Closed

Comments

@renky
Copy link
Contributor

renky commented Jul 12, 2023

Laravel Version

10.13.5

PHP Version

8.2.x

Database Driver & Version

Mysql 5.7

Description

File Http/Client/Request
method: data() and json()

The Methods both have the return type array (declared in PHPDoc @return array).

But there is a possibility that it returns null - in case of a non-valid json body.
json_decode will return null if the content cannot be decoded or the depth is to high.

so either the return type shall be changed to ?array or the json function should be extended like so

$this->data = json_decode($this->body(), true) ?? [];

It isn't a huge issue, but when using PHPStan and doing something like that:

$data = $request->data() ?? [];

it is always complaining about left part can never be null due to return values...

@driesvints
Copy link
Member

Thanks but we don't consider invalid DocBlock types as bugs. Please see our contribution guide: https://laravel.com/docs/10.x/contributions#bug-reports

We're welcoming PRs to fix any issues.

renky pushed a commit to renky/laravel-framework that referenced this issue Jul 24, 2023
taylorotwell pushed a commit that referenced this issue Jul 24, 2023
Co-authored-by: Dominik <dominik@profi-webspace.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants