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

[11.x] Fix docblock of \Illuminate\Http\Response #51823

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

seriquynh
Copy link
Contributor

@seriquynh seriquynh commented Jun 18, 2024

\Illuminate\Http\Response::morphToJson() sometimes returns json_encode() result that could be either string or false (a boolean value). So, it's return docblock must contain string|false.

    /**
     * Morph the given content into JSON.
     *
     * @param  mixed  $content
     * @return string|false
     */
    protected function morphToJson($content)
    {
        if ($content instanceof Jsonable) {
            return $content->toJson();
        } elseif ($content instanceof Arrayable) {
            return json_encode($content->toArray());
        }

        return json_encode($content);
    }

@crynobone
Copy link
Member

If the possible value is just false, shouldn't it be @return string|false?

@bulletproof-coding
Copy link

If you put the return type in line not in dock block will it be a breaking change?

@seriquynh
Copy link
Contributor Author

I saw other places also used "string|false", so I changed to "@return string|false".

@seriquynh
Copy link
Contributor Author

@marius-mcp It is not a breaking change, it a bug. This method absolutely return either string or false, I do not change it's behavior.

@bulletproof-coding
Copy link

@seriquynh ok, bug, but dock blocks are not restrictive. If you declare the function as

: string|false

it will throw exception if the return type will differ.

@taylorotwell taylorotwell merged commit fe9a599 into laravel:11.x Jun 18, 2024
28 checks passed
@seriquynh seriquynh deleted the fix-docblock branch June 18, 2024 23:35
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

Successfully merging this pull request may close these issues.

4 participants