Skip to content

Conversation

@dereuromark
Copy link
Contributor

Summary

When a docblock has only some @param annotations (e.g., only the middle parameter documented), the fixer was adding missing params in the wrong order.

Before this fix:

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

Would be "fixed" to:

/**
 * @param array<string> $lines
 * @param int $indent
 * @param Node $parent
 */

After this fix:

/**
 * @param Node $parent
 * @param array<string> $lines
 * @param int $indent
 */

Changes

  • Rewrote canAddMissingParams() to properly track positions and insert params in correct order
  • Params before the first existing @param are queued and inserted before it
  • Params after an existing @param are inserted after it
  • Added test case for this scenario

Test plan

  • New test case added for middle-param scenario
  • All existing tests pass (82 tests, 88 assertions)
  • PHPStan passes
  • PHPCS passes

🤖 Generated with Claude Code

When a docblock has only some `@param` annotations (e.g., the middle
parameter), the fixer was adding missing params at the wrong position.
For example, with method `foo($a, $b, $c)` and only `@param ... $b`
documented, the fixer would add `$a` and `$c` after `$b` instead of
in the correct order.

This fix ensures params are inserted in the correct positions:
- Params before the first existing `@param` are inserted before it
- Params after an existing `@param` are inserted after it

Adds test case for this scenario.

🤖 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:50
@dereuromark dereuromark force-pushed the fix-param-order-on-add branch from df0fbbd to bee1fb1 Compare November 27, 2025 12:51
@dereuromark dereuromark changed the title Fix param order when adding missing @param annotations Fix param order when adding missing @param annotations Nov 27, 2025
@dereuromark dereuromark merged commit 76b3bc9 into master Nov 27, 2025
4 checks passed
@dereuromark dereuromark deleted the fix-param-order-on-add branch November 27, 2025 12:52
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