You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently I worked on hinted query builder Closures in Laravel, but it appears they have been having some issues and it was concluded to not do so for the foreseeable future: laravel/framework#48562
Since these not being hinted leaves some blind spots when analyzing the code with PHPStan+Larastan should I try to instead integrate this with Larastan, and if so what would be the best path to do so?
One take away from the original PR was that it might be better to hint things as mixed rather then void in places where where the output is never used since existing code may return values for various reasons.
The main driver behind this is that we had some issues where we had the wrong types, but phpstan was unable to catch the issue because there are no hints in Laravel as to what it expects the closures to look like.
A somewhat exaggerated example of a bad hint that is not detected:
User::leftJoin('items', function (\Illuminate\Database\Eloquent\Builder$join): void {
$join->on('items.user_id', '=', 'user.id')->where('items.sold', 1);
})
What it actually should look like:
User::leftJoin('items', function (\Illuminate\Database\Query\JoinClause$join): void {
$join->on('items.user_id', '=', 'user.id')->where('items.sold', 1);
})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Recently I worked on hinted query builder Closures in Laravel, but it appears they have been having some issues and it was concluded to not do so for the foreseeable future: laravel/framework#48562
Since these not being hinted leaves some blind spots when analyzing the code with PHPStan+Larastan should I try to instead integrate this with Larastan, and if so what would be the best path to do so?
One take away from the original PR was that it might be better to hint things as
mixed
rather thenvoid
in places where where the output is never used since existing code may return values for various reasons.The main driver behind this is that we had some issues where we had the wrong types, but phpstan was unable to catch the issue because there are no hints in Laravel as to what it expects the closures to look like.
A somewhat exaggerated example of a bad hint that is not detected:
What it actually should look like:
Beta Was this translation helpful? Give feedback.
All reactions