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

Relation generics and PHPStan lvl 9 #101

Merged
merged 4 commits into from
Sep 4, 2024
Merged

Conversation

SanderMuller
Copy link
Contributor

Similar to the work on https://github.com/staudenmeir/laravel-adjacency-lis I've introduced generic support for the BelongsToThrough relation, and increasing PHPStan to the max level was quite easy!

src/Relations/BelongsToThrough.php Outdated Show resolved Hide resolved
src/Traits/BelongsToThrough.php Show resolved Hide resolved
@staudenmeir
Copy link
Owner

Awesome, thanks!

@staudenmeir
Copy link
Owner

@SanderMuller FYI: PHPStan released v1.12.1 yesterday and that suddenly reports the return type getRelationExistenceQuery() as invalid (it's not caused by my changes in 949c7d9):
https://github.com/staudenmeir/belongs-to-through/actions/runs/10697087338/job/29653550927

Not sure if that's a bug or PHPStan just hadn't been able to properly analyze the Eloquent and Query Builder construct until now.

I fixed it with a @var comment for now: 7a9f8b4

@staudenmeir staudenmeir merged commit b71fc5b into staudenmeir:main Sep 4, 2024
8 checks passed
@SanderMuller
Copy link
Contributor Author

@SanderMuller FYI: PHPStan released v1.12.1 yesterday and that suddenly reports the return type getRelationExistenceQuery() as invalid (it's not caused by my changes in 949c7d9): https://github.com/staudenmeir/belongs-to-through/actions/runs/10697087338/job/29653550927

Not sure if that's a bug or PHPStan just hadn't been able to properly analyze the Eloquent and Query Builder construct until now.

I fixed it with a @var comment for now: 7a9f8b4

Weird $query->select() seems to already trigger a "downgrade" of the inferred type to Illuminate/Database/Query/Builder instead of retaining \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> despite the select() method returning $this, which should AFAIK keep its caller scope. I first thought maybe the Laravel Framework made a change, but it indeed seems to be related to the latest PHPStan update, though I'm not sure why. There's quite some changes in phpstan/phpstan-src@1.12.0...1.12.1 😅 maybe we should accept your fix for now

@staudenmeir
Copy link
Owner

There's quite some changes in phpstan/phpstan-src@1.12.0...1.12.1

Yeah... My best guess would be that it's related to one of the commits about mixins.

@SanderMuller
Copy link
Contributor Author

SanderMuller commented Sep 4, 2024

There's quite some changes in phpstan/[email protected]

Yeah... My best guess would be that it's related to one of the commits about mixins.

I'm actually getting the same PHPStan errors on my other projects. This seems to be the related issue phpstan/phpstan#11624 and larastan/larastan#2032, mixins are indeed mentioned there

Copy link
Contributor

@calebdw calebdw left a comment

Choose a reason for hiding this comment

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

Looks like I was a little late to catch this before it was merged, but here's some suggested improvements

src/Relations/BelongsToThrough.php Show resolved Hide resolved
src/IdeHelperServiceProvider.php Show resolved Hide resolved
src/Relations/BelongsToThrough.php Show resolved Hide resolved
src/Relations/BelongsToThrough.php Show resolved Hide resolved
src/Relations/BelongsToThrough.php Show resolved Hide resolved
src/Relations/BelongsToThrough.php Show resolved Hide resolved
src/Relations/BelongsToThrough.php Show resolved Hide resolved
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