RemovedPHP4StyleConstructors: fix bug with nested constructs#751
Merged
Conversation
7f4df89 to
041e187
Compare
041e187 to
3ddefab
Compare
Inspired by upstream issue 2178, I checked that the same bug didn't exist in the related PHPCompatibility sniff and found that it did.
Fixed by simply skipping to the function closer after examining each function declaration as the content of the function is not our concern.
This should also make the sniff faster.
Notes:
* In PHPCS 2.3.x, anonymous classes do not yet have their own token, so the class name determination would be incorrect as the upstream method searches for the first `T_STRING` and in this case, that would be the name of the first function in the class, nested or otherwise.
Added a work-around for this.
* Interfaces can declare deprecated constructors as well and should trigger the error.
Includes unit test for both interfaces, classes with abstract methods as well as for the original case: functions in a nested anonymous class.
Also added some additional unit tests to raise code coverage.
3ddefab to
eec125b
Compare
wimg
approved these changes
Dec 13, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Inspired by upstream issue squizlabs/PHP_CodeSniffer#2178, I checked that the same bug didn't exist in the related PHPCompatibility sniff and found that it did.
Fixed by simply skipping to the function closer after examining each function declaration as the content of the function is not our concern.
This should also make the sniff faster.
Notes:
T_STRINGand in this case, that would be the name of the first function in the anonymous class.Added a work-around for this.
Includes unit test for both interfaces, classes with abstract methods as well as for the original case: functions in a nested anonymous class.
Also added some additional unit tests to raise code coverage.