Allow configuring custom PHPDoc tags that reference classes#7895
Open
ruudk wants to merge 1 commit intorectorphp:mainfrom
Open
Allow configuring custom PHPDoc tags that reference classes#7895ruudk wants to merge 1 commit intorectorphp:mainfrom
ruudk wants to merge 1 commit intorectorphp:mainfrom
Conversation
In our project we use a custom PHPDoc tag `@throwable-from` paired with a
PHPStan rule that validates the referenced class and method exist. For example:
```php
/**
* @throwable-from NotificationHandler::createPayload
* @throwable-from UserSpecificPayloadNotificationHandler::createPayloadForUser
*/
final class MessageShouldBeIgnoredException extends Exception
```
Rector's unused import removal does not recognize class references in custom
PHPDoc tags and removes the corresponding use statements. The class resolver
in PhpDocTagGenericUsesDecorator was hardcoded to only `@uses`, `@used-by`,
and `@see`.
This adds a configurable list of additional PHPDoc tag names that should be
treated as containing class references, so their imports are preserved:
```php
RectorConfig::configure()
->withPhpDocTagsWithClassReference(['@throwable-from']);
```
Member
|
I'd prefer generic solution that would not require configuration per project. |
Contributor
Author
|
How would you like to do that with a custom phpdoc like this? I believe this was done for performance reasons? |
Member
|
I am on mobile, how about just remove the : This of course need to verify other decorator that doing similar logic on different docblock node to avoid overwritten. |
Contributor
Author
|
Yeah i think that would be fine too! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In our project we use a custom PHPDoc tag
@throwable-frompaired with a PHPStan rule that validates the referenced class and method exist. For example:Rector's unused import removal does not recognize class references in custom PHPDoc tags and removes the corresponding use statements. The class resolver in PhpDocTagGenericUsesDecorator was hardcoded to only
@uses,@used-by, and@see.This adds a configurable list of additional PHPDoc tag names that should be treated as containing class references, so their imports are preserved:
/cc @samsonasik