forked from squizlabs/PHP_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Various updates to enum sniff fixes #1
Merged
kukulich
merged 13 commits into
kukulich:php81-enum
from
jrfnl:feature/update-enum-sniff-fixes
Jan 19, 2022
Merged
Various updates to enum sniff fixes #1
kukulich
merged 13 commits into
kukulich:php81-enum
from
jrfnl:feature/update-enum-sniff-fixes
Jan 19, 2022
Conversation
This file contains 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
* Test case file 1 should contain both a duplicate and a non-duplicate enum. * Test case file 2 should contain an enum which was already declared in file 1 to verify cross-file detection.
Ensure that all aspects of the sniff are tested for enums. While these tests pass, if you look at the actual error message output, you will see some weirdness (declaration name for the `enum` set as `string`). This should be fixed once PR 3534 has been merged.
Ensure that all aspects of the sniff are tested for enums. While these tests pass, if you look at the actual error message output, you will see some weirdness (declaration name for the `enum` set as `string`). This should be fixed once PR 3534 has been merged.
Ensure that backed enum signatures are included in the tests. Note: the adjusted tests _without a space between the enum name and the colon_ will fail until PR 3534 has been merged.
Test more aspects of the sniff are applied correctly to enums.
The enum test was placed _below_ a test which was marked as testing a specific situation at the end of a file, which invalidated the "end of file" test. Fixed by moving the new test up.
Add a _valid_ test case for a backed enum. Note: this new test will fail until PR 3534 has been merged.
Let's also test the implements keyword when used with an enum.
Ensure that backed enum signatures are included in the tests. As this sniff retrieves the class name itself instead of using the `File::getDeclarationName()` method, these tests _will_ find the name correctly (not mistake the type for the name), but _may_ include the colon in the name as the "name end" determination checks on scope opener and whitespace and doesn't take the colon for the type declaration into account.
Only use tabs when in the test cases when they serve a specific purpose.
Let's also test that `$this` in a non-static enum method doesn't get flagged.
The test as-it-was, wasn't actually testing anything. As the sniff is about control structures, the `enum` needs to be nested in one before the test would fail without the fix,
kukulich
pushed a commit
that referenced
this pull request
Apr 22, 2022
The `Util\Standards::getInstalledStandardPath()` method returns either a string or `null`, however the `strpos()` method which is used in both the `Util\Common::isPharFile()` method, as well as in the follow-on condition, only accepts a `string` as `$haystack`. As of PHP 8.1, this will generate a deprecation notice `strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated`. Discovered while testing an external standard against PHPCS `master` on PHP 8.1. Fixed now.
kukulich
pushed a commit
that referenced
this pull request
Apr 22, 2022
On PHP 8.1, passing `null` to `strtolower()` generates a `strtolower(): Passing null to parameter #1 ($string) of type string is deprecated` notice. The `File::getDeclarationName()` will return `null` for anonymous classes, so we need an extra safeguard here. This fix is covered by the existing unit tests and was exposed when running the tests on PHP 8.1 with `error_reporting` set to `E_ALL`.
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.
As discussed upstream, here are some (mostly) minor tweaks for PR squizlabs#3482
Feel free to squash these fixes into your original commits for a clean history.
Notes:
Squiz.Commenting.InlineComment
was breaking a test which had to be at the end of the file. Fixed by moving the new test up.Squiz.WhiteSpace.ControlStructureSpacing
wasn't actually testing anything. Fixed by wrapping it in a control structure.Squiz.Classes.ValidClassName
sniff needed an additional fix to be able to handle backed enums.