Move "snake case" related utility to dedicated SnakeCaseHelper + bug fix in method #2190
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.
Move "snake case" related utility to dedicated SnakeCaseHelper
The "snake case" related utility method is only used by a small set of sniffs, so is better placed in a dedicated class.
This commit moves the
get_snake_case_name_suggestion()
method to the newWordPressCS\WordPress\Helpers\SnakeCaseHelper
and starts using that class in the relevant sniffs.Note:
It is expected for PHPCSUtils to have dedicated methods for the same at some point in the future. If/when those methods become available, it is recommended for the sniffs to start using the PHPCSUtils methods.
With that in mind, this class is marked as not part of the public API.
Related to #1465
SnakeCaseHelper::get_suggestion(): bug fix - underscore handling
The
SnakeCaseHelper::get_suggestion()
method should have no opinion on the use of leading/trailing/double underscores in a name.In practice, however, it did and the suggested name would be incorrect.
Fixed now.
Includes tests to safeguard this fix in the
ValidFunctionName
test case file, though the current methodology for testing would not catch a regression.To illustrate the issue - originally, the error messages for these new tests would read:
With the fix, the error messages for the new tests read: