New error code for Squiz.Commenting.FunctionComment
: MissingParamType
#127
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.
Description
When a docblock comment is provided for a function parameter, but no valid type information is supplied*, the error message (and code) from PHP_CodeSniffer is misleading. This pull request aims to fix this by introducing a new error code for these cases. This could be considered a breaking change as rulesets may need to be adjusted to accommodate this new error code.
* Some editors will create boiler-plate docblocks like this, expecting the developer to write the correct information.
Additionally, while working on the above change, I noticed that in some cases an invalid suggestion of adding a type hint for this specific case was being provided. I have included a fix for this in this pull request.
Before this change, the following code would be annotated as
after this change, the same code would be annotated as
(Note the difference for line 3 ("Missing parameter name" versus "Missing parameter type"), and the lack of error for line 6.)
Here's an example from the existing test file for this sniff:
PHP_CodeSniffer/src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc
Lines 789 to 802 in d84144d
Suggested changelog entry
[Squiz.Commenting.FunctionComment] New error code
MissingParamType
will be used instead ofMissingParamName
when a parameter name is provided, but not its type. Additionally, invalid type hint suggestion will no longer be provided in these cases.Types of changes
PR checklist