-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Filters/ExactMatch: deprecate the getBlacklist()
and getWhitelist()
methods
#203
Filters/ExactMatch: deprecate the getBlacklist()
and getWhitelist()
methods
#203
Conversation
* The `getBlockedFiles()` method will be made abstract and therefore required | ||
* in v4.0 and this method will be removed. | ||
* If both methods are implemented, the new `getBlockedFiles()` method will take precedence. | ||
* | ||
* @return array | ||
*/ | ||
abstract protected function getBlacklist(); |
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.
Can we replace the method with a non- abstract implementation, so downstream code won't need to implement a deprecated method?
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.
@derrabus Thanks for the feedback.
I was struggling a little with whether to do that or not, as that would mean we can no longer enforce that at least one of each of getBlacklist/getBlockedFiles
and getWhitelist/getAllowedFiles
is required to be implemented and making the new methods abstract
would introduce a breaking change in a minor.
Only way I can think of still safeguarding it, would be to remove all four method declarations from the ExactMatch
class and using method_exists()
checks and throwing an exception is any of these sets don't have a corresponding method, but removing the method declarations also makes it much less obvious what the class expects and would require significantly more documentation to be added to the class.
Not sure it's worth the overhead for the (hopefully) short period until the 4.0 release, especially considering that based on a simple code search, there are no external classes extending the ExactMatch
class.
What do you think ?
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.
The abstract class could contain implementations of both methods calling each other, with a recursion detection. If a recursion is detected, you throw because in that case the downstream class hasn't implemented either of them.
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.
@derrabus Hmm.. feels a bit like overengineering for something which isn't a real life issue anyway - see the impact analysis (same link I posted in the underlying issue)
The PHP native implements Serializable
vs __serialize()
conundrum also comes to mind.
Based on the code in this PR, the following situations are possible for custom Filter
classes which extend ExactMatch
:
- Do nothing, i.e. only implements the old
abstract
methods.
Impact:- Will continue to work fine without deprecation notices in combination with any PHPCS 3.x release.
- Will break in combination with PHPCS 4.0 or higher.
- Implement both the old and the new methods in whichever way they prefer (one pointing to the other or visa versa).
Impact:- Will work cross-version with any PHPCS 3.x or 4.x release without notices.
- Once support for PHPCS 3.x is dropped, the implementation of the "old" methods can be removed.
- Implement only the "new" methods.
Impact:- Will not work in combination with PHPCS 3.x.
- Well, that would be one package which is ready early for PHPCS 4.x ;-)
61b77a3
to
9d4af7a
Compare
There has been some discussion about the new function names in #198. Based on that discussion, the |
I like current patch as is, basically.
So, my +0.5 :-) |
9d4af7a
to
a1831b0
Compare
If there are no other comments/feedback to this PR, I will merge it tomorrow. |
…)` methods Deprecate the `getBlacklist()` and `getWhitelist()` methods and introduce the `getDisallowedFiles()` and `getAllowedFiles()` replacement methods. When available in child classes, the `getDisallowedFiles()` and `getAllowedFiles()` methods will take precedence over the deprecated `getBlacklist()` and `getWhitelist()` methods. Fixes 198
a1831b0
to
3baecd7
Compare
Rebased without changes to be sure. Merging once the build passes. |
Description
Deprecate the
getBlacklist()
andgetWhitelist()
methods and introduce the++getBlockedFiles()
getDisallowedFiles()
++ andgetAllowedFiles()
replacement methods.When available in child classes, the
++getBlockedFiles()
getDisallowedFiles()
++ andgetAllowedFiles()
methods will take precedence over the deprecatedgetBlacklist()
andgetWhitelist()
methods.Suggested changelog entry
ExactMatch::getBlacklist()
andExactMatch::getWhitelist()
methods are deprecated and will be removed in the 4.0 release.ExactMatch::getDisallowedFiles()
andExactMatch::getAllowedFiles()
methodsExactMatch
cross-version compatible with both PHP_CodeSniffer 3.9.0+ as well as 4.0+, implement the newgetDisallowedFiles()
andgetAllowedFiles()
methods.getDisallowedFiles()
andgetAllowedFiles()
methods as well as thegetBlacklist()
andgetWhitelist()
are available, the new methods will take precedence over the old methods.Related issues/external references
Fixes #198
Covered by the tests which were added in #201