Skip to content

Conversation

@dereuromark
Copy link
Contributor

Summary

The VariableWrong check in DocBlockParamSniff was producing false positives when a doc block only documented some parameters (e.g., only those needing complex type hints like array<string>).

Problem

Given this code:

/**
 * @param array<string> $lines
 */
protected function parseBlocks(Node $parent, array $lines, int $indent): void

The sniff would report:

Doc Block param variable `$lines` should be `$parent`

This happened because params were compared by position (1st doc block param vs 1st method param) rather than by name.

Solution

Match doc block params to method params by variable name instead of position. This allows:

  • Partial documentation (only documenting params that need complex type hints)
  • Correct error reporting when a doc block param doesn't exist in the method signature at all

Test case

/**
 * @param array<string> $lines  <- This is the 2nd method param, but 1st in docblock
 */
protected function parseBlocks(Node $parent, array $lines, int $indent): void

Previously: Error (false positive)
Now: No error (correct - $lines exists in method signature)

🤖 Generated with Claude Code

Previously, when a doc block only documented some parameters (e.g.,
only those needing complex type hints like `array<string>`), the sniff
would compare params by position rather than by name, causing false
positives.

For example, this code:
```php
/**
 * @param array<string> $lines
 */
protected function parseBlocks(Node $parent, array $lines, int $indent): void
```

Would incorrectly report: "Doc Block param variable `$lines` should be
`$parent`" because it was comparing the first doc block param with the
first method param positionally.

Now the sniff matches doc block params to method params by variable
name, allowing partial documentation to work correctly. Only params
that don't exist in the method signature at all are reported as errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@dereuromark dereuromark marked this pull request as ready for review November 27, 2025 12:14
@dereuromark dereuromark merged commit 8b6e91e into master Nov 27, 2025
4 checks passed
@dereuromark dereuromark deleted the fix-docblock-param-variable-order branch November 27, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants