Skip to content

Removed @mixin Builder comment from Model.php #2923

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

Closed
wants to merge 2 commits into from

Conversation

promatik
Copy link

@promatik promatik commented May 1, 2024

Fix for #2922.

This change fdfb5e5#diff-284e164f76aeb13f424d154f9208d91fdbb0112b0a50ad8b1dfa237176f03cf2 introduced a breaking change for phpstan, it now wrongly infers models as Illuminate\Database\Eloquent\Model, instead of it's main class.

Salut @GromNaN!
As the author of that change, is it necessary? Can we go back to what it was?

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@promatik promatik requested a review from a team as a code owner May 1, 2024 02:16
@promatik promatik requested a review from GromNaN May 1, 2024 02:16
@GromNaN
Copy link
Member

GromNaN commented May 1, 2024

Thanks for the feedback. Could you provide an example of static analysis that is broken with this change, that was not before. Thanks.

@GromNaN
Copy link
Member

GromNaN commented May 2, 2024

From my POV, this annotation enables autocompletion of builder's methods in PHPStorm.
If that creates an issue, the solution will be to declare all the methods with @method annotation.

@promatik
Copy link
Author

promatik commented May 2, 2024

UPDATE:

@GromNaN I think I found the issue;

use ...
use MongoDB\Laravel\Query\Builder as QueryBuilder;
use ...

Probably PHPStorm understands that Builder is actually the QueryBuilder, but PHPStand doesn't.

I changed Builder to QueryBuilder and PHPStan is not throwing me any errors 🎉

Also updated the PR.
Can you please test this on PHPStorn?

@GromNaN
Copy link
Member

GromNaN commented May 2, 2024

That's a different class, the exposed methods are wrong with this change.
Example, MongoDB\Laravel\Eloquent\Builder::aggregates returns AggregationBuilder | mixed while MongoDB\Laravel\Query\Builder::aggregates returns AggregationBuilder | self.

I tried to reproduce with PHPStan but didn't find the bug.
https://phpstan.org/r/10adb986-2c43-4b77-9a80-6f31d562441f

Try removing or changing the @mixin annotation to see the error.

@promatik
Copy link
Author

promatik commented May 2, 2024

Hey @GromNaN!

Yeah, sorry for the mistake, now I see it's a different class.

Anyway, I can see mixin works as expected in your demo, but I can't fix my issue 🫤
With the mixing there, my model wrongly becomes a Illuminate\Database\Eloquent\Model.

 ------ -------------------------------------------------------------------------------------- 
  Line   2024_04_26_225522_add_share_slug_to_calls_table.php
 ------ --------------------------------------------------------------------------------------
  :16    Access to an undefined property Illuminate\Database\Eloquent\Model::$share_code.
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property
 ------ --------------------------------------------------------------------------------------

By the way, I'm using larastan/larastan and I think the problem comes from there, because I just tried phpstan alone, and everything works 🤷‍♂️

Let's move the issue to Larastan 👌
larastan/larastan#1940

@promatik
Copy link
Author

Hey @GromNaN, sorry for bothering again.
Based on this comment; larastan/larastan#1940 (comment)

Might this be an issue on this implementation? I have no idea about these inner ways of work of stan.

I'm trying to upgrade to v4.3, but the 30+ phpstan errors are keeping me away form it.

@promatik promatik reopened this May 22, 2024
@GromNaN GromNaN mentioned this pull request May 27, 2024
3 tasks
@GromNaN
Copy link
Member

GromNaN commented May 30, 2024

Fixed by #2981

@GromNaN GromNaN closed this May 30, 2024
@promatik promatik deleted the patch-1 branch May 31, 2024 09:57
@promatik
Copy link
Author

Great!
Thank you @GromNaN 🎉

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.

2 participants