-
Notifications
You must be signed in to change notification settings - Fork 160
Proxies and interceptors #59
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
Conversation
Merging in parent develop
…-standard into ProxiesAndInterceptors
* | ||
* @var string | ||
*/ | ||
protected $warningMessage = 'Proxies and interceptors MUST never be explicitly requested in constructors.'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to split this sniff into two sniffs to comply with single responsibility principle.
Or make it more generic and extensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have concerns regarding your comment:
- This sniff covers one statement from Technical Guidelines and thats why it sounds logical to me to have this one rule.
- Splitting into two sniffs doesn't sound good in performance prospective (make same check twice).
- On the other hand, making it more generic sounds good to me. The name can be changed to
DiscouragedDependenciesSniff
(or something like this) and$warnNames
property can be public and will be replaceable viaruleset.xml
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- On the other hand, making it more generic sounds good to me. The name can be changed to DiscouragedDependenciesSniff (or something like this) and $warnNames property can be public and will be replaceable via ruleset.xml.
I do like the sound of the latter - I didn't realise that this could be done. Nice :)
*/ | ||
private $warnNames = [ | ||
'proxy', | ||
'plugin' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the task was not clear enough, the expectation was to prevent Interceptor
classes being referenced directly. Interceptors are auto-generated classes.
It may make sense to run these tests against Magento codebase and see if Plugin reference detection also makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'll add interceptors first and then look at plugins as you suggest.
/** | ||
* // Rule find: constructor use of proxy class | ||
*/ | ||
class Foo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proxy classes are the one which have \Proxy
suffix. Interceptor classes always have \Interceptor
suffix. These can be accurately detected and should raise error.
Plugin classes have arbitrary names and thus are difficult to catch. These rules may have accuracy issues and can raise warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is based on names of constructor types and variables there will be a false-positive issue. In discussion with @lenaorobei it was felt that keeping these as warnings was of utility despite this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even is it's bad naming it's worth pointing developers that class name with Interceptor
and Proxy
suffix is not a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address suggestions above.
To confirm from above:
|
Let them be in the sniff code. Ruleset will be an extension point (if needed in future). @paliarush do you have additional comments? |
@maderlock thanks for your contribution! I just had quick discussion with @paliarush and we agreed following:
|
I'll do as you suggest, though I'm still a little concerned about false positives given the matching of variable names. |
With the changes above it looks like we should no longer be detecting proxy/interceptor in variable names. The logic should now be:
Should we allow classes with Proxy or Interceptor in the non-suffix position, e.g. /Vendor/Module/Proxy/SomethingElse - or should this be a warning or error? |
Yes, that's right.
Non-suffix position should be fine. We dont need to trigger any warnings in this case. To make sure everything works as expected, I suggest running this check against Magento codebase: |
Sorry for the delay - I've been rather ill. I'll jump back on this when I can. Thanks for bearing with me. |
@maderlock do you need any help with this PR? |
…r interceptor exactly
…tandard into develop # Conflicts: # Magento2/ruleset.xml
* develop: REPO-66: [EQP][Sniffs Consolidation] Deliver Magento Coding Standard to magento2ce Fixed name in ruleset Remove multiple empty line Fix line length sniff when using translations Made InsecureFunctionSniff in line with UnsecureFunctionsUsageTest Removed CyclomaticComplexity Removed DateTime sniff Removed DateTime sniff Removed DateTime sniff magento#67: Remove Magento2.Exceptions.Namespace Removed ObjectInstantiation sniff XssTemplateSniff does not detect some use cases [Enhancement] DiscouragedFunction rule improvement [Enhancement] DiscouragedFunction rule improvement Namespace conflict with core rules Removed unstable Annotation sniffs
Could not get properties passing from ruleset.xml, so I've had to ignore that change request. Otherwise I've made the requested changes and merged into the updated structure under Magento2 (rather than Magento). I've tested the rule against the Magento codebase and the only errors that come out are valid ones, so I'm happy that it's working as expected (in addition to the tests passing). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address my minor suggestions.
* develop: Added exclude for `_files` and `*Test.php` files Fixed test false-positive findings Update README.md
Minor suggestions addressed and latest develop merged |
AC-1102: Static test to verify self-closing tags for non-void html elements
Fix #18 New rule to ensure proxies and interceptors are never explicitly requested in constructors