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

Update ValidFunctionNames Sniff to allow for non-valid names in extended classes. #623

Merged
merged 4 commits into from
Jul 25, 2016

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 19, 2016

Fixes #507

This allows for classes which extend a parent class or implement an interface to use method names which do not comply with the "don't start methods with a double underscore" and snake case rules so they can overload parent methods without an issue being raised.
This was previously already implemented for snake case, but not for double underscore.

I've also synced the class with the parent class it uses and applied any relevant changes to the overloaded methods and removed some code which can defer to the parent.

Also:

  • removed some code which was no longer needed (had to do with the private _ method names)
  • updated the documentation here and there
  • added more extensive unit tests
  • fixed a wrongly tagged message and improved the wording of it

Please see the individual commits for more details.

There was one change in the parent class - which I have implemented -, which I was not sure about as it changes the result of one unit test.

Basically, before, function names (outside class scope) were allowed to start with a double underscore.
The change in the parent does allow for methods where the name only consists of underscores, like __(), but does not allow function names which also contain other characters to start with a double underscore unless they are a PHP magic function name, i.e. __autoload().

jrfnl added 4 commits July 19, 2016 18:06
* Defer to the parent class for the list of magic methods - as long as it's up to date, no need to maintain this in WPCS. Historically these properties were `private`, but they have since been changed to `protected` and are therefore now ok to use.
* Bow out early for closures.
* Allow for `__autoload()` functions outside of the class scope.
* Allow for function names only consisting of underscores like `__()`.

Last relevant change to the parent class was made in v2.5.1 and as the WPCS minimum version requirement is currently 2.6.0, we're good.
…he check for prefixed private methods had been removed.
Includes reordering of the various conditions within the function for optimal performance.

Fixes #507.
* Fix wrong error code for MethodNameInvalid.
* Make sure suggested alternative names don't start or end with an underscore.
* Add a number of unit tests for:
	- PHP magic methods (now handled via parent)
	- SoapClient methods
* Minor documentation fixes.
* Minor improvement of the MethodNameInvalid error message.
@JDGrimes
Copy link
Contributor

There was one change in the parent class - which I have implemented -, which I was not sure about as it changes the result of one unit test.

Basically, before, function names (outside class scope) were allowed to start with a double underscore.
The change in the parent does allow for methods where the name only consists of underscores, like __(), but does not allow function names which also contain other characters to start with a double underscore unless they are a PHP magic function name, i.e. __autoload().

I think this change is correct. PHP's docs don't specify that only class methods with double-underscores are reserved, but rather all functions:

Caution PHP reserves all function names starting with __ as magical. It is recommended that you do not use function names with __ in PHP unless you want some documented magic functionality.

@jrfnl
Copy link
Member Author

jrfnl commented Jul 19, 2016

Yes, that ;-)

@JDGrimes JDGrimes added this to the 0.10.0 milestone Jul 25, 2016
@JDGrimes JDGrimes merged commit 4bf32d1 into develop Jul 25, 2016
@JDGrimes JDGrimes deleted the WPCS/feature/issue-507-soap-methods branch July 25, 2016 21:18
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.

False positive: only PHP magic methods should be prefixed with a double underscore
3 participants