Skip to content

Add configurable naming for variadic arguments (opt-out) and related tests/docs#16

Merged
savinmikhail merged 2 commits into
mainfrom
codex/investigate-github-issue-15
Mar 7, 2026
Merged

Add configurable naming for variadic arguments (opt-out) and related tests/docs#16
savinmikhail merged 2 commits into
mainfrom
codex/investigate-github-issue-15

Conversation

@savinmikhail
Copy link
Copy Markdown
Owner

@savinmikhail savinmikhail commented Mar 6, 2026

Motivation

  • Allow the rector to convert positional arguments that map to a variadic parameter into deterministic named arguments like name1, name2 while keeping the feature configurable.
  • Preserve existing behavior by making variadic naming opt-out and avoid surprising changes for callers that rely on the previous behavior.
  • Document the design and testing strategy for variadics to clarify behavior and edge cases.

Description

  • Added a new configuration key ALLOW_NAMED_VARIADIC_ARGUMENTS to AddNamedArgumentsRector and expose configuration indices via STRATEGY and ALLOW_NAMED_VARIADIC_ARGUMENTS, with the variadic option defaulting to enabled.
  • Implemented variadic handling by mapping arguments beyond the last declared parameter to the last parameter when it is variadic, and naming each variadic item deterministically as <paramName>1, <paramName>2, etc., using internal counters.
  • Introduced resolveParameterForArgumentIndex() helper in both AddNamedArgumentsRector and DefaultStrategy to unify argument-to-parameter mapping, and added hasVariadicArguments() to early-skip refactoring when the variadic option is disabled.
  • Updated configure() parsing and validation to accept the new boolean variadic option and to preserve existing strategy configuration, added README clarification for the new option, and added docs/issue-15-implementation-plan.md describing the approach.

Testing

  • Added unit tests and fixtures: tests/VariadicDisabledStrategy/AddNamedArgumentsRectorTest.php with tests/VariadicDisabledStrategy/Fixture/variadic_disabled.php.inc, and tests/DefaultStrategy/Fixture/variadic.php.inc and variadic_mixed_signature.php.inc were updated/added to assert variadic naming behavior.
  • Ran the project's PHPUnit test suite (vendor/bin/phpunit) including the new and updated fixtures, and all tests passed.

@savinmikhail savinmikhail merged commit e27df68 into main Mar 7, 2026
5 of 6 checks passed
@savinmikhail savinmikhail mentioned this pull request Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant