Skip to content

Conversation

peterfox
Copy link
Contributor

Changes

  • Adds a new check in ParamAnalyzer to look for the use of func_get_args within a method
  • Adds a test fixture for RemoveUnusedConstructorParamRector to skip when func_get_args

Why

I found this issue popping up if func_get_args was used in a constructor. In theory there's also func_get_arg(int position) to consider as well but it's a question of either:

  1. refactor the analyzer to consider param position or
  2. just outright skip any methods that use func_get_arg() as well

@TomasVotruba TomasVotruba merged commit 220f33b into rectorphp:main Jun 19, 2025
45 checks passed
@TomasVotruba
Copy link
Member

Nice one, thank you 👍

@@ -164,4 +168,17 @@ private function isParamUsed(Node $node, Param $param): bool
$arguments = $this->funcCallManipulator->extractArgumentsFromCompactFuncCalls([$node]);
return $this->nodeNameResolver->isNames($param, $arguments);
}

private function isFuncGetArgsCall(Node $node): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should can use VariadicFunctionLikeDetector::isVariadic() that cover 3 functions:

  • func_get_arg
  • func_get_args
  • func_num_args

public function isVariadic(FunctionLike $functionLike): bool

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created PR for it:

to merge functionality into ParamAnalyzer and remove the VariadicFunctionLikeDetector as double work and cause manually called.

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.

3 participants