diff --git a/rules/Naming/Naming/ConflictingNameResolver.php b/rules/Naming/Naming/ConflictingNameResolver.php index 426ea54b417..445465f88af 100644 --- a/rules/Naming/Naming/ConflictingNameResolver.php +++ b/rules/Naming/Naming/ConflictingNameResolver.php @@ -8,10 +8,10 @@ use PhpParser\Node\Expr\Closure; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; +use Rector\Core\NodeManipulator\FunctionLikeManipulator; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Naming\ExpectedNameResolver\MatchParamTypeExpectedNameResolver; use Rector\Naming\PhpArray\ArrayFilter; -use Rector\NodeNameResolver\NodeNameResolver; final class ConflictingNameResolver { @@ -24,8 +24,8 @@ public function __construct( private readonly ArrayFilter $arrayFilter, private readonly BetterNodeFinder $betterNodeFinder, private readonly ExpectedNameResolver $expectedNameResolver, - private readonly NodeNameResolver $nodeNameResolver, - private readonly MatchParamTypeExpectedNameResolver $matchParamTypeExpectedNameResolver + private readonly MatchParamTypeExpectedNameResolver $matchParamTypeExpectedNameResolver, + private readonly FunctionLikeManipulator $functionLikeManipulator ) { } @@ -67,7 +67,7 @@ private function resolveConflictingVariableNamesForNew(ClassMethod | Function_ | return $this->conflictingVariableNamesByClassMethod[$classMethodHash]; } - $paramNames = $this->collectParamNames($functionLike); + $paramNames = $this->functionLikeManipulator->resolveParamNames($functionLike); $newAssignNames = $this->resolveForNewAssigns($functionLike); $nonNewAssignNames = $this->resolveForNonNewAssigns($functionLike); @@ -79,21 +79,6 @@ private function resolveConflictingVariableNamesForNew(ClassMethod | Function_ | return $protectedNames; } - /** - * @return string[] - */ - private function collectParamNames(ClassMethod | Function_ | Closure $functionLike): array - { - $paramNames = []; - - // params - foreach ($functionLike->params as $param) { - $paramNames[] = $this->nodeNameResolver->getName($param); - } - - return $paramNames; - } - /** * @return string[] */ diff --git a/src/NodeManipulator/ClassMethodPropertyFetchManipulator.php b/src/NodeManipulator/ClassMethodPropertyFetchManipulator.php index 0acb67af97d..a06a58db1e2 100644 --- a/src/NodeManipulator/ClassMethodPropertyFetchManipulator.php +++ b/src/NodeManipulator/ClassMethodPropertyFetchManipulator.php @@ -21,7 +21,8 @@ final class ClassMethodPropertyFetchManipulator public function __construct( private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser, private readonly NodeNameResolver $nodeNameResolver, - private readonly BetterNodeFinder $betterNodeFinder + private readonly BetterNodeFinder $betterNodeFinder, + private readonly FunctionLikeManipulator $functionLikeManipulator ) { } @@ -93,7 +94,7 @@ public function findAssignsToPropertyName(ClassMethod $classMethod, string $prop { $assignExprs = []; - $paramNames = $this->getParamNames($classMethod); + $paramNames = $this->functionLikeManipulator->resolveParamNames($classMethod); $this->simpleCallableNodeTraverser->traverseNodesWithCallable( (array) $classMethod->stmts, @@ -123,17 +124,4 @@ function (Node $node) use ($propertyName, &$assignExprs, $paramNames, $classMeth return $assignExprs; } - - /** - * @return string[] - */ - private function getParamNames(ClassMethod $classMethod): array - { - $paramNames = []; - foreach ($classMethod->getParams() as $param) { - $paramNames[] = $this->nodeNameResolver->getName($param); - } - - return $paramNames; - } } diff --git a/src/NodeManipulator/FunctionLikeManipulator.php b/src/NodeManipulator/FunctionLikeManipulator.php index 6caad67f118..9f8bd03bb37 100644 --- a/src/NodeManipulator/FunctionLikeManipulator.php +++ b/src/NodeManipulator/FunctionLikeManipulator.php @@ -57,4 +57,18 @@ public function getReturnedLocalPropertyNames(FunctionLike $functionLike): array return $returnedLocalPropertyNames; } + + /** + * @return string[] + */ + public function resolveParamNames(FunctionLike $functionLike): array + { + $paramNames = []; + + foreach ($functionLike->getParams() as $param) { + $paramNames[] = $this->nodeNameResolver->getName($param); + } + + return $paramNames; + } }