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

feat: infer nullable type information by filled/blank function calls #1843

Merged
merged 1 commit into from Feb 12, 2024

Conversation

tpetry
Copy link
Contributor

@tpetry tpetry commented Feb 12, 2024

The result value of the blank and filled helpers imply some type information that is currently not supported by Larastan. To be precise, the blank helper will return true on null while the filled will return false. This enhanced type inference is especially usefull when working with nullable Eloquent attributes:

if (filled($model->value)) {
  executeSomething($model->value);
}

Currently, PHPStan will report errors as null can't be passed to executeSomething. But the value can never be null because of a true result of the filled check. The new stubs help PHPStan to narrow the types of values passed to filled and blank functions.

Resolves #1290

Changes

Added blank and filled helpers to the helper stubs

Breaking changes

None

@canvural
Copy link
Collaborator

Thank you! Finally we can merge this 😄 Hope to make a release this week 👍🏽

@canvural canvural merged commit 5a37b3d into larastan:2.x Feb 12, 2024
30 checks passed
@tpetry tpetry deleted the patch-blank-filled-nullable branch February 13, 2024 06:25
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.

blank helper should track nulls from variable
2 participants