Fix DocBlockParamAllowDefaultValueSniff positional mismatch on partial @param lists#58
Merged
dereuromark merged 1 commit intomasterfrom Apr 13, 2026
Conversation
…@param lists When a docblock's @param list omitted intermediate parameters (e.g. only documenting $row and $errors while skipping $accountId between them), the sniff matched docblock tags against the method signature by position. The second @param ($errors) was compared against signature slot 1 ($accountId, int), producing a false-positive "missing type int" fix that added `|int` to the documented type. DocBlockParamTypeMismatchSniff correctly matched by name, removed the `|int`, and the two sniffs entered an infinite fixer loop until phpcbf bailed with "FAILED TO FIX". Index the signature by parameter name and look up each @param by the parsed valueNode->parameterName instead.
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.
Summary
DocBlockParamAllowDefaultValueSniffmatched docblock@paramtags against the method signature by position (\$methodSignature[\$paramCount++]). When a docblock's@paramlist omitted intermediate parameters, positional indexing misaligned the comparison and the sniff produced false-positive "missing type" fixes.Reproduction
@paramtags:\$row,\$errors.\$row,\$accountId,\$property,\$errors.\$errors(count=1) mapped to signature slot 1, which isint \$accountId.\$errorswas "missing typeint" and rewrotelist<string> \$errors→list<string>|int \$errors.DocBlockParamTypeMismatchSniff(which correctly matches by name) then removed the bogus|int.FAILED TO FIX.Fix
Build a
\$signatureByNamemap keyed on the parameter variable name, parse each@param's\$valueNodefirst, then look up the matching signature entry by\$valueNode->parameterName. Partial or out-of-order docblocks now skip params they don't mention instead of misaligning them against the wrong signature slot.Test
Added a regression fixture (
partialDocBlockmethod intests/_data/DocBlockParamAllowDefaultValue/before.phpandafter.php) that reproduces the infinite fixer loop on master and passes on this branch. Verified by stashing the sniff change and rerunning the test — it fails with the exact bad rewrite (list<string>|int \$errors).Full suite (91 tests) still green.