Skip to content

Commit

Permalink
[Performance] Remove unnecessary FunctionLikeParamPositionNodeVisitor (
Browse files Browse the repository at this point in the history
…#5491)

* [Performance] Remove unnecessary FunctionLikeParamPositionNodeVisitor

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Jan 22, 2024
1 parent e1effe7 commit aa66151
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 44 deletions.
2 changes: 0 additions & 2 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::COMMENTS,
\Rector\NodeTypeResolver\Node\AttributeKey::VIRTUAL_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PARAMETER_POSITION,
\Rector\NodeTypeResolver\Node\AttributeKey::RAW_VALUE,
);

Expand All @@ -73,6 +72,5 @@
\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NAME,
\Rector\NodeTypeResolver\Node\AttributeKey::COMMENTS,
\Rector\NodeTypeResolver\Node\AttributeKey::VIRTUAL_NODE,
\Rector\NodeTypeResolver\Node\AttributeKey::PARAMETER_POSITION,
\Rector\NodeTypeResolver\Node\AttributeKey::RAW_VALUE,
);
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Param;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
Expand All @@ -25,7 +24,6 @@
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
Expand Down Expand Up @@ -152,18 +150,13 @@ public function refactor(Node $node): ?Node
return null;
}

private function inferParam(Class_ $class, Param $param, PhpDocTagNode | Attribute $dataProviderNode): Type
private function inferParam(Class_ $class, int $parameterPosition, PhpDocTagNode | Attribute $dataProviderNode): Type
{
$dataProviderClassMethod = $this->resolveDataProviderClassMethod($class, $dataProviderNode);
if (! $dataProviderClassMethod instanceof ClassMethod) {
return new MixedType();
}

$parameterPosition = $param->getAttribute(AttributeKey::PARAMETER_POSITION);
if ($parameterPosition === null) {
return new MixedType();
}

/** @var Return_[] $returns */
$returns = $this->betterNodeFinder->findInstanceOf((array) $dataProviderClassMethod->stmts, Return_::class);
if ($returns !== []) {
Expand Down Expand Up @@ -339,14 +332,14 @@ private function refactorClassMethod(ClassMethod $classMethod, Class_ $class, ar
{
$hasChanged = false;

foreach ($classMethod->getParams() as $param) {
foreach ($classMethod->getParams() as $parameterPosition => $param) {
if ($param->type instanceof Node) {
continue;
}

$paramTypes = [];
foreach ($dataProviderNodes as $dataProviderNode) {
$paramTypes[] = $this->inferParam($class, $param, $dataProviderNode);
$paramTypes[] = $this->inferParam($class, $parameterPosition, $dataProviderNode);
}

$paramTypeDeclaration = TypeCombinator::union(...$paramTypes);
Expand Down
5 changes: 0 additions & 5 deletions src/NodeTypeResolver/Node/AttributeKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ final class AttributeKey
*/
public const DO_NOT_CHANGE = 'do_not_change';

/**
* @var string
*/
public const PARAMETER_POSITION = 'parameter_position';

/**
* @var string
*/
Expand Down
3 changes: 0 additions & 3 deletions src/NodeTypeResolver/NodeScopeAndMetadataDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node\Stmt;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\CloningVisitor;
use Rector\NodeTypeResolver\NodeVisitor\FunctionLikeParamPositionNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
use Rector\NodeTypeResolver\PHPStan\Scope\ScopeFactory;
use Rector\PhpParser\NodeTraverser\FileWithoutNamespaceNodeTraverser;
Expand All @@ -20,15 +19,13 @@ final class NodeScopeAndMetadataDecorator
public function __construct(
CloningVisitor $cloningVisitor,
private readonly PHPStanNodeScopeResolver $phpStanNodeScopeResolver,
FunctionLikeParamPositionNodeVisitor $functionLikeParamPositionNodeVisitor,
private readonly ScopeFactory $scopeFactory,
private readonly FileWithoutNamespaceNodeTraverser $fileWithoutNamespaceNodeTraverser
) {
$this->nodeTraverser = new NodeTraverser();

// needed for format preserving printing
$this->nodeTraverser->addVisitor($cloningVisitor);
$this->nodeTraverser->addVisitor($functionLikeParamPositionNodeVisitor);
}

/**
Expand Down

This file was deleted.

0 comments on commit aa66151

Please sign in to comment.