mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
[NodeTypeResolver] add Param type to VariableTypeResolverTest
This commit is contained in:
parent
d2396be720
commit
67471f4728
@ -6,6 +6,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Param;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\NodeTypeResolver\Contract\NodeTypeResolverAwareInterface;
|
||||
use Rector\NodeTypeResolver\Contract\PerNodeTypeResolver\PerNodeTypeResolverInterface;
|
||||
@ -58,6 +59,17 @@ final class VariableTypeResolver implements PerNodeTypeResolverInterface, NodeTy
|
||||
return $variableNode->getAttribute(Attribute::CLASS_NAME);
|
||||
}
|
||||
|
||||
if ($parentNode instanceof Param) {
|
||||
$variableName = $variableNode->name;
|
||||
$variableType = $this->nodeTypeResolver->resolve($parentNode->type);
|
||||
|
||||
if ($variableType) {
|
||||
$this->typeContext->addVariableWithType($variableName, $variableType);
|
||||
|
||||
return $variableType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
array_map(function (UseUse $useUse) {
|
||||
return $useUse;
|
||||
}, []);
|
@ -8,7 +8,7 @@ use Rector\NodeTypeResolver\Tests\AbstractNodeTypeResolverTest;
|
||||
|
||||
final class VariableTypeResolverTest extends AbstractNodeTypeResolverTest
|
||||
{
|
||||
public function test(): void
|
||||
public function testNewAndAssign(): void
|
||||
{
|
||||
$nodes = $this->getNodesWithTypesForFile(__DIR__ . '/Source/SomeClass.php.inc');
|
||||
$variableNodes = $this->nodeFinder->findInstanceOf($nodes, Variable::class);
|
||||
@ -17,4 +17,13 @@ final class VariableTypeResolverTest extends AbstractNodeTypeResolverTest
|
||||
$this->assertSame('SomeNamespace\AnotherType', $variableNodes[1]->getAttribute(Attribute::TYPE));
|
||||
$this->assertSame('SomeNamespace\AnotherType', $variableNodes[2]->getAttribute(Attribute::TYPE));
|
||||
}
|
||||
|
||||
public function testCallbackArgumentTypehint(): void
|
||||
{
|
||||
$nodes = $this->getNodesWithTypesForFile(__DIR__ . '/Source/callbackArgumentTypehint.php.inc');
|
||||
$variableNodes = $this->nodeFinder->findInstanceOf($nodes, Variable::class);
|
||||
|
||||
$this->assertSame('SomeNamespace\UseUse', $variableNodes[0]->getAttribute(Attribute::TYPE));
|
||||
$this->assertSame('SomeNamespace\UseUse', $variableNodes[1]->getAttribute(Attribute::TYPE));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user