Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Generate noinspections PHPStorm tags #905

Merged
merged 4 commits into from
Apr 21, 2020
Merged

Conversation

mzglinski
Copy link
Contributor

When using write option for models eq

 php artisan ide-helper:models --smart-reset --write 

Generated PHPDoc has fully qualified names, about which PHPStorm complains (as it should). However, this is problematic since later during automatic code cleanup tasks these names are replaced with use statements. This generates unnecessary changes in the files, especially if some developers forget to run code cleanup. Later on, all of this stays in the git history.

As a solution, this PR adds a new option to the model command. --phpstorm-noinspections eg

php artisan ide-helper:models --smart-reset --write --phpstorm-noinspections

This will include two PHPStorm inspections at the end of the PHPDoc comment

 * @noinspection PhpFullyQualifiedNameUsageInspection
 * @noinspection PhpUnnecessaryFullyQualifiedNameInspection

which will stop PHPStorm from replacing the autogenerated FQN with use statements.

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

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

I like it, seems "practically useful".

(although personally I've been living with this warning for years and no team member ever complained, but 🤷‍♀️)

However: could you please add a test for this? Thanks!

@mfn
Copy link
Collaborator

mfn commented Mar 31, 2020

  • @noinspection PhpFullyQualifiedNameUsageInspection
  • @noinspection PhpUnnecessaryFullyQualifiedNameInspection

Wait, why does it need both?

I'm on 2020.1 Beta and only PhpFullyQualifiedNameUsageInspection is recognized, the other seems not to have an impact?

@mzglinski
Copy link
Contributor Author

Sure, I will write a test tomorrow ;)

As for PhpUnnecessaryFullyQualifiedNameInspection please refer to https://www.jetbrains.com/help/phpstorm/php-unnecessary-fully-qualified-name.html

This is for relations basically, they are also FQN but all models are usually in the same namespace so FQN is not necessary and PHPStorm removes their namespaces on code cleanup/code reformat.

@mfn
Copy link
Collaborator

mfn commented Apr 1, 2020

As for PhpUnnecessaryFullyQualifiedNameInspection please refer to https://www.jetbrains.com/help/phpstorm/php-unnecessary-fully-qualified-name.html

This is for relations basically, they are also FQN but all models are usually in the same namespace so FQN is not necessary and PHPStorm removes their namespaces on code cleanup/code reformat.

Thanks for the details!

I think it would be great if you could add this as a code comment with the block if ($this->phpstorm_noinspections) { so it's clear as to why (adding the link would be also nice).

thanks

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

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

LGTM 👍

ping @barryvdh

@mzglinski
Copy link
Contributor Author

Is there any chance for this to be merged in the near future?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants