Skip to content

Skip internal variadic callables and fix variadic argument naming handling#20

Merged
savinmikhail merged 2 commits into
mainfrom
codex/review-and-fix-issue-#18
Mar 19, 2026
Merged

Skip internal variadic callables and fix variadic argument naming handling#20
savinmikhail merged 2 commits into
mainfrom
codex/review-and-fix-issue-#18

Conversation

@savinmikhail
Copy link
Copy Markdown
Owner

@savinmikhail savinmikhail commented Mar 19, 2026

Motivation

  • Prevent generating invalid named arguments for internal/native variadic callables (e.g. sprintf) while preserving naming for user-defined variadic parameters.
  • Fix a bug where variadic arguments had their name set but were not appended to the resulting args list or marked as a change.
  • Clarify the README behavior for ALLOW_NAMED_VARIADIC_ARGUMENTS so users know when internal callables are skipped.

Description

  • In AddNamedArgumentsRector::refactor detect if the call has variadic arguments and obtain the function reflection via Reflection::getFunctionReflection, and skip refactoring when the variadic call is to an internal function (isInternal).
  • Reworked addNamesToArgs to correctly handle variadic parameters by assigning an Identifier, appending the argument to $namedArgs, and setting $hasChanges before continuing the loop, and moved non-variadic naming into the correct branch.
  • Updated README.md to explain the nuanced behavior for ALLOW_NAMED_VARIADIC_ARGUMENTS and the difference between user-defined and internal variadic callables.
  • Added tests/DefaultStrategy/Fixture/internal_variadic.php.inc and adjusted tests/DefaultStrategy/Fixture/variadic.php.inc to reflect that internal variadic functions like sprintf are no longer converted.

Testing

  • Ran the test suite with vendor/bin/phpunit and all tests completed successfully.
  • The added/updated fixtures under tests/DefaultStrategy/Fixture were exercised and matched expected outcomes.

…DME and tests

### Motivation

- Prevent generating unknown named arguments for internal/native callables (e.g., `sprintf`) which would be rejected by PHP while still allowing named variadic synthesis for user-defined callables.
- Make the behavior around `ALLOW_NAMED_VARIADIC_ARGUMENTS` explicit in the documentation.
- Add/adjust fixtures to cover both internal variadic and user-defined variadic cases.

### Description

- Add detection of function reflection via `Reflection::getFunctionReflection` and pass a `shouldKeepVariadicArgsPositional` flag into `addNamesToArgs` when the callable is internal.
- Modify `addNamesToArgs` to keep variadic arguments positional for internal callables and continue naming variadic entries for user-defined callables (using incremental names like `values1`, `values2`).
- Rework argument naming flow to centralize naming logic and ensure the node's `args` are replaced only when changes were made.
- Update `README.md` to clarify the default behavior of `ALLOW_NAMED_VARIADIC_ARGUMENTS` and add an explanation of differences between user-defined and internal callables, and add/modify test fixtures (`tests/DefaultStrategy/Fixture/internal_variadic.php.inc` and `tests/DefaultStrategy/Fixture/variadic.php.inc`).

### Testing

- Ran the test suite with `vendor/bin/phpunit` which executed the updated fixtures and rule tests successfully.
…dling

### Motivation
- Prevent generating invalid named arguments for internal/native variadic callables (e.g. `sprintf`) while preserving naming for user-defined variadic parameters.
- Fix a bug where variadic arguments had their `name` set but were not appended to the resulting args list or marked as a change.
- Clarify the README behavior for `ALLOW_NAMED_VARIADIC_ARGUMENTS` so users know when internal callables are skipped.

### Description
- In `AddNamedArgumentsRector::refactor` detect if the call has variadic arguments and obtain the function reflection via `Reflection::getFunctionReflection`, and skip refactoring when the variadic call is to an internal function (`isInternal`).
- Reworked `addNamesToArgs` to correctly handle variadic parameters by assigning an `Identifier`, appending the argument to `$namedArgs`, and setting `$hasChanges` before continuing the loop, and moved non-variadic naming into the correct branch.
- Updated `README.md` to explain the nuanced behavior for `ALLOW_NAMED_VARIADIC_ARGUMENTS` and the difference between user-defined and internal variadic callables.
- Added `tests/DefaultStrategy/Fixture/internal_variadic.php.inc` and adjusted `tests/DefaultStrategy/Fixture/variadic.php.inc` to reflect that internal variadic functions like `sprintf` are no longer converted.

### Testing
- Ran the test suite with `vendor/bin/phpunit` and all tests completed successfully.
- The added/updated fixtures under `tests/DefaultStrategy/Fixture` were exercised and matched expected outcomes.
@savinmikhail savinmikhail merged commit 71aa7a2 into main Mar 19, 2026
6 checks passed
@savinmikhail
Copy link
Copy Markdown
Owner Author

#18

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