-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
Extract re-usable code from Sniff.php into new package #1465
Comments
@GaryJones I'd been thinking about this myself and my take on this is slightly different. For a number of "groups" of methods which are in the
I'd need to look into how this would work with PHPCS autoloading, but with the I don't think the other standards is a consideration as such. They can just declare WPCS as a dependency - which most already do anyway as they use WPCS sniffs - and either, at this moment, use the WPCS At this moment, there are only very few methods in the WPCS The group of "function call parameter" methods definitely come to mind. I actually wrote those with PHPCS in mind and have - not to put too fine a point to it - basically been testing them in WPCS and PHPCompatibility before pulling them to PHPCS. However, the typical place to pull these in PHPCS would be to the Another thing to take into consideration before pulling anything to PHPCS, is copyright. This is basically the reason why for sniffs which I've written for WPCS, but which were generically applicable, I've often pulled them to both WPCS as well as PHPCS around the same time as at that moment, I was the only one who had touched the code, and as I pulled the sniff to both, there is no copyright issue. |
That would work for me. But equally, that doesn't preclude those traits from being in their own package.
It doesn't have to be a consideration, but in open source spirit, if there's some code that is in WPCS that could be of use to someone else, it benefits all the users to make it available and have that consistent comprehensive functionality handled in one place. Neutron doesn't have WPCS as a dependency at all. VIPCS does, but only because it builds upon the WPCS-specific logic, as opposed to the general PHPCS helper methods found in WPCS. The former may change, but it may still want to use the latter without needing to require the whole of WPCS.
Could they be pushed into PHPCS as traits?
IANAL, but so long as attribution is maintained, we should be good. |
That's not a question to ask or discuss here, but in the PHPCS repo.
But copyright does.
And attribution is never maintained, nor the history, if the code is moved out of this repo, so see my previous reply. |
Oh and just to be clear: that's what making WPCS a dependency does. If we reorganize code to make that easier, all the better, but it's not an argument for a separate package. |
Could they be, and would it be a good idea at all, to have a helper class where these helper methods are static? Something like They would probably all have to be rewritten, since most (if not all) have |
FYI and to follow up on my previous comment where I said I'd been thinking about this anyway: I've opened an issue about a refactor for PHPCS - squizlabs/PHP_CodeSniffer#2189
With all this in mind, I think we should hold off on the move to traits until it has crystallized what will go in to PHPCS and how, to prevent doing a lot of unnecessary (double) work. After we've upgraded to the PHPCS version containing the refactor, we can evaluate what's left of the WPCS utility methods and whether moving some of these to traits and/or static classes would still make sense and how that should be organized. Makes sense ? |
…izingFunctionsTrait` (#2259) Move sanitization functions related functionality to dedicated `SanitizingFunctionsTrait` The sanitization function lists are only used by a small set of sniffs, so are better placed in a dedicated trait. The choice for a `trait` over a `class` is due to the `public` properties allowing for adding additional functions to the lists. Moving both the base function lists + the `public` properties to the same trait will allow us to encapsulate all the functionality related to the use of these lists in one place. The `$sanitizingFunctions` and the `$unslashingSanitizingFunctions` property, containing the base lists, have also been made `private`. Checking whether or not something is a sanitization function should now be done by calling the `SanitizingFunctionsTrait::is_sanitizing_function()` or the `SanitizingFunctionsTrait::is_sanitizing_and_unslashing_function()` method. Related to #1465
Sniff.php contains a lot of helper methods: re-usable bits of code that could be used in one or more sniffs, e.g.:
is_foreach_as()
(part of GlobalVariablesOverride: detect variable overrides in global namespace #1457)is_token_in_test_method()
is_test_class()
is_assignment()
is_in_isset_or_empty()
get_array_access_key()
is_comparison()
All of the methods are non-WPCS / non-WP specific (or could be made to be). It would be even nicer if some of these could be moved into PHPCS itself (cc @gsherwood), but if not, then having a separate package, perhaps including the WordPress-specific methods as well, would allow the helper methods to be re-used by other WP-specific coding standards (Neutron, VIP CS, etc.)
Sniff.php
is very long, and while that's not a bad thing on its own, it does make maintenance trickier, and re-using all of that non-WPCS goodness harder too.The text was updated successfully, but these errors were encountered: