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

Prevent generation of incorrect property annotation #1665

Conversation

skyler544
Copy link
Contributor

Summary

When generating Eloquent annotations on a model that uses a factory, the tool generates an incorrect $use_factory property with the following annotation:
@property-read \App\Models\TFactory|null $use_factory

Then, when running a static analysis tool (like Larastan), it fails:
PHPDoc tag @property-read for property App\Models\User::$use_factory contains unknown class App\Models\User\TFactory.

This pull request introduces a workaround for that problem by filtering out the getUseFactoryAttribute method from the reflected methods in src/Console/ModelsCommand::getPropertiesFromMethods().

With the changes from this PR, running artisan ide-helper:models -n -W -R in our project root removes the faulty @property-read annotations.

Credit for this idea goes to LauJosefsen.

See issue 1664 for more details.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Existing tests have been adapted and/or new tests have been added
  • Update the README.md
  • Code style has been fixed via composer fix-style

@barryvdh barryvdh merged commit ead24b1 into barryvdh:master Jan 29, 2025
17 checks passed
@skyler544 skyler544 deleted the hack/1664-incorrect-property-annotation-on-models-with-factories branch January 31, 2025 07:40
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