[Core][Naming] Move collecting param names method to FunctionLikeManipulator (#2347)

* [Core][Naming] Move collecting param names method to FunctionLikeManipulator

* use getParams() as interface

* [ci-review] Rector Rectify

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Abdul Malik Ikhsan 2022-05-22 23:53:13 +07:00 committed by GitHub
parent 68906c7e17
commit 8fbc6582f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 34 deletions

View File

@ -8,10 +8,10 @@ use PhpParser\Node\Expr\Assign;
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 @@ final class ConflictingNameResolver
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 @@ final class ConflictingNameResolver
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 @@ final class ConflictingNameResolver
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[]
*/

View File

@ -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 @@ final class ClassMethodPropertyFetchManipulator
{
$assignExprs = [];
$paramNames = $this->getParamNames($classMethod);
$paramNames = $this->functionLikeManipulator->resolveParamNames($classMethod);
$this->simpleCallableNodeTraverser->traverseNodesWithCallable(
(array) $classMethod->stmts,
@ -123,17 +124,4 @@ final class ClassMethodPropertyFetchManipulator
return $assignExprs;
}
/**
* @return string[]
*/
private function getParamNames(ClassMethod $classMethod): array
{
$paramNames = [];
foreach ($classMethod->getParams() as $param) {
$paramNames[] = $this->nodeNameResolver->getName($param);
}
return $paramNames;
}
}

View File

@ -57,4 +57,18 @@ final class FunctionLikeManipulator
return $returnedLocalPropertyNames;
}
/**
* @return string[]
*/
public function resolveParamNames(FunctionLike $functionLike): array
{
$paramNames = [];
foreach ($functionLike->getParams() as $param) {
$paramNames[] = $this->nodeNameResolver->getName($param);
}
return $paramNames;
}
}