Skip to content
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

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Dec 31, 2023

Description

Deprecate the getBlacklist() and getWhitelist() methods and introduce the getBlockedFiles() ++getDisallowedFiles()++ and getAllowedFiles() replacement methods.

When available in child classes, the getBlockedFiles() ++getDisallowedFiles()++ and getAllowedFiles() methods will take precedence over the deprecated getBlacklist() and getWhitelist() methods.

Suggested changelog entry

  • Issue 198: The abstract ExactMatch::getBlacklist() and ExactMatch::getWhitelist() methods are deprecated and will be removed in the 4.0 release.
    • In version 4.0, these methods will be replaced with abstract ExactMatch::getDisallowedFiles() and ExactMatch::getAllowedFiles() methods
    • To make Filters extending ExactMatch cross-version compatible with both PHP_CodeSniffer 3.9.0+ as well as 4.0+, implement the new getDisallowedFiles() and getAllowedFiles() methods.
      • When both the getDisallowedFiles() and getAllowedFiles() methods as well as the getBlacklist() and getWhitelist() 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

* 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();

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?

Copy link
Member Author

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 ?

Copy link

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.

Copy link
Member Author

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:

  1. 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.
  2. 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.
  3. 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 ;-)

@jrfnl
Copy link
Member Author

jrfnl commented Jan 13, 2024

There has been some discussion about the new function names in #198. Based on that discussion, the getBlockedFiles() method name has been replaced with getDisallowedFiles().

src/Filters/ExactMatch.php Outdated Show resolved Hide resolved
@stronk7
Copy link
Contributor

stronk7 commented Jan 13, 2024

I like current patch as is, basically.

  • It will make things to be as they are now (abstract) in 4.x with the new methods.
  • It's documented (in phpdocs, in release notes - it will, ....).
  • it's easy to support both 3.x and 4.x if needed to.
  • impact seems to be small, not requiring any sort of extra check or complexity.

So, my +0.5 :-)

@jrfnl jrfnl force-pushed the feature/198-filter-deprecate-whitelist-blacklist-methods branch from 9d4af7a to a1831b0 Compare January 19, 2024 04:51
@jrfnl
Copy link
Member Author

jrfnl commented Jan 22, 2024

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
@jrfnl jrfnl force-pushed the feature/198-filter-deprecate-whitelist-blacklist-methods branch from a1831b0 to 3baecd7 Compare January 25, 2024 16:17
@jrfnl
Copy link
Member Author

jrfnl commented Jan 25, 2024

Rebased without changes to be sure. Merging once the build passes.

@jrfnl jrfnl merged commit fda00a0 into master Jan 25, 2024
44 checks passed
@jrfnl jrfnl deleted the feature/198-filter-deprecate-whitelist-blacklist-methods branch January 25, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filters/ExactMatch: deprecate getBlacklist() and getWhitelist() methods
3 participants