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

Question: What is the difference between WordPress_AbstractFunctionRestrictionsSniff and Generic_Sniffs_PHP_ForbiddenFunctionsSniff? #630

Closed
grappler opened this issue Jul 25, 2016 · 2 comments

Comments

@grappler
Copy link
Member

I am looking to create a few extra sniffs and was not sure which to use as a base.

There is also Generic_Sniffs_PHP_DeprecatedFunctionsSniff which extends Generic_Sniffs_PHP_ForbiddenFunctionsSniff

@jrfnl
Copy link
Member

jrfnl commented Jul 25, 2016

My two pennies:

Generic_Sniffs_PHP_ForbiddenFunctionsSniff is a great one to extend if you simply want to forbid a number of functions and mention their potential replacement. It can use regex patterns as well for matching function names. However the error message is not very flexible, so you can't change it.

The Generic_Sniffs_PHP_DeprecatedFunctionsSniff should not be used as the basis for extending. It uses Reflection to check for deprecation on native PHP functions. AFAICS, this will not work for non-native PHP functions. It also does not provide info on what a potential replacement could be.

WordPress_AbstractFunctionRestrictionsSniff allows for a more modular approach, providing groups of functions and people can use the sniff, but still disable one (or more) of the groups for a project.
It offers wildcard matching, but not pattern matching. And if #626 will be merged, you can selectively whitelist functions which would match the wildcard.

All of these currently suffer from #611 - they don't check in callbacks. I would guess that that will only be solved for the abstract and as WP uses callbacks a lot, that would probably be the safest choice looking to the future.

@grappler
Copy link
Member Author

Thanks, that answers my question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants