-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Increase PHPStan level to 5 #244
Conversation
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
@calebdw Regarding the PHPDoc fix for |
@staudenmeir, the asterisks are valid, higher levels of PHPStan are going to require that the inner types are defined. |
The problem is that the array is being parsed incorrectly and it thinks an Try to update to: // remove the space
/** @param array<array-key,(callable(\Illuminate\Database\Eloquent\Relations\Relation): mixed)|string>|string $relations */
// or try wrapping the array in parens
/** @param (array<array-key, (callable(\Illuminate\Database\Eloquent\Relations\Relation): mixed)|string>)|string $relations */ If this doesn't work then it's likely a phpstan parse error, try to replicate on https://phpstan.org/try and open an issue with phpstan |
Thanks @calebdw. These updates don't fix the error, unfortunately. |
Actually, this looks like it's because parameter types are not covariant which means you can't define a narrower type: https://phpstan.org/r/0e4afb98-6c78-4076-9b50-5035cb0d8faf The solution is to either use $users = User::all()->load([
'ancestorPosts' => fn (Relation $query) => $query->orderBy('id'),
]);
// or
$users = User::all()->load([
'ancestorPosts' => fn ($query) => $query->orderBy('id'),
]); |
Thanks @calebdw. I typed the closures to get autocompletion from PhpStorm. Do you know why the Eloquent builder mixin doesn't work here with
|
@staudenmeir, the mixin is working fine when I add it to the framework tests. The issue may be that we're still waiting on larastan/larastan#1990 to be merged so that Larastan supports Laravel >= 11.15 |
@staudenmeir I also had to ignore this error in my other projects where I went to level 5/6 I've created a PR to fix this: #245 |
When laravel/framework#52724 gets released, we can remove the ignored error. |
Thanks @calebdw and @SanderMuller. |
There is only one type of PHPStan error:
The affected code looks like this:
The first issue is that the parameter type of
Collection::load()
is incorrect. The callable function actually gets passed a relationship, not an Eloquent builder:However, this fix doesn't resolve the error:
The error only goes away when you change the parameter's type to
Relation
(despiteHasManyDeep
being a subclass ofRelation
):With this change, however, PHPStan can't handle methods calls anymore despite the
Relation
class's Eloquent builder mixin:@calebdw As discussed.
@SanderMuller Maybe you have an idea?