Skip to content

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

Closed
@renky

Description

@renky

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions