-
Notifications
You must be signed in to change notification settings - Fork 160
Require @see annotations for plugin classes and methods #173
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
Comments
Isn't this kind of superfluous noise?
Additionally, the PHPStorm Magento Plugin adds
I like to avoid all annotations or comments that don't add any new information, because
|
I agree, @Vinai . Thinking about this sentence though:
In this case we should rather request the docblock to specify a union type (until we have native union types in PHP 8) Also, I usually advice to name the plugin after the pluginized class/interface and delegate actual operations to a service with a meaningful name, especially if there are plugins for multiple methods. I don't think this should be strictly enforced by the coding standard, but it makes the described reason a non-issue. |
You may be correct. In some instances the annotation may be redundant. For plugins that are intercepting more than one class the target class cannot be declared in the signature. I think this could be resolved by updating the implementation to exclude the requirement on such lines, though there's no link that can be utilized by any IDE The PhpStorm Magento plugin does resolve this as you've pointed out, but not all teams use PhpStorm.
This is an interesting approach. Right now I typically give the plugin itself a meaningful name and do the work in there or in another class (with the plugin prepping the parameters) depending on the size of the work that needs to be done. I've had in the past at least one scenario where I've created multiple plugins for the same class and had them separated. In your naming scenario they could not be. |
This is only true if the plugin is used to intercept the same method multiple classes that don't share a common type (e.g. an interface). The final scenario you mention
seems unrelated to the issue at hand, i.e. the plugin subject can be part of the signatures of the plugin methods. |
Clicking on the plugin icon in PHPStorm and seeing a list of identically named plugin classes is one of my favorite pet peevs. It's really not helpul to see for example a list of In my experience is much more helpful if the plugins are named after their purpose, e.g. |
I used to think the same, but I like to see from a glance, for which classes a module has plugins, and di.xml does not serve that well. Understand your argument though. Maybe I don't use this plugin icon often enough with methods that have more than one or two plugins. |
It's an unusual habit to have an IDE-driven design and I don't think that should be a consideration for this PR. If we could assume everyone was using PHPStorm we could switch to tabs instead of spaces and reduce our processing time and storage space by a significant amount 😉 Not considering PHPStorm or the Magento plugin for it, I do feel like this would be a helpful feature for plugins that intercept more than one class. However I also think that is a rare use case and probably a code smell by itself since that feels like a risky practice. I think if the standard "one class per plugin" paradigm is followed then the plugin is self-documenting as has been discussed. To the point about being able to see which classes or plugins are available, this PR would not help with that. |
For me, this approach is a violation of best practices - don't describe the implementation in DocBlock (method/class description). The declaration in di.xml is an implementation. If someone changes it (removes or adds plugin declaration) you will have a wrong statement in the DocBlock. We need to remember that the plugin can be added by one module and disabled by another. If you check the di.xml declarations, you will have a clear understanding of the current state, but not with the @see annotation |
Don't use a plugin to wrap multiple methods. Use a single plugin with a single method for each. Then use that to call another method that contains the shared logic. Let the code, not documentation, be the source of truth. |
…o-coding-standard-383 [Imported] Fix warnings detected by phpcs & phpunit
Rule
@see
annotation to the class(es) that it is intercepting.@see
annotation to the method(s) it is interceptingReason
This rule would improve QOL for developers by providing a definitive link to what a plugin is intercepting. This can be especially useful for plugins that are intercepting more than one class.
Implementation
An implementation has been written by Mediotype and can be modified for this standard. Our implementation checks:
Vendor\Module\Model\Plugin\*
orVendor\Module\Plugin\*
@see
tag@see
tagThe text was updated successfully, but these errors were encountered: