Skip to content

Conversation

@marcreichel
Copy link
Contributor

This pull request adds more detailed type hints to the when() helper function, allowing PHPStan to better analyze the output. Allowing the usage of when() in higher PHPStan levels (9+) where the output of when() gets provided to another method that requires a specific parameter type.

Examples

// Before
when(random_int(0, 1), 42); // <- mixed

// After
when(random_int(0, 1), 42); // <- 42|null
// Before
when(true, 42); // <- mixed

// After
when(true, 42); // <- 42
// Before
when(random_int(0, 1), 42, 1337); // <- mixed

// After
when(random_int(0, 1), 42, 1337); // <- 42|1337

@github-actions
Copy link

github-actions bot commented Feb 8, 2026

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@marcreichel marcreichel marked this pull request as ready for review February 8, 2026 12:26
Copy link
Contributor

@shaedrich shaedrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have sworn, these types were already part of the helper—I couldn't have been more wrong apparently 🤯

All the better, that someone took on the task 👍🏻

Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com>
@marcreichel marcreichel requested a review from shaedrich February 8, 2026 13:06
Copy link
Contributor

@shaedrich shaedrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

But I can neither approve nor reject your PR, however, Taylor will eventually.

@taylorotwell taylorotwell merged commit a008950 into laravel:12.x Feb 9, 2026
70 checks passed
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.

3 participants