This commit is contained in:
TomasVotruba 2017-11-01 21:32:16 +01:00
parent 7f9e1a3497
commit bfc26a9e5b
6 changed files with 51 additions and 22 deletions

View File

@ -207,19 +207,6 @@ You can:
'code': 'string'
```
- **remove unused argument** (@todo consider d with `ArgumentReplacerRector`)
```yml
rectors:
Rector\Rector\Dynamic\ArgumentRemoverRector:
# class
'Doctrine\ORM\Persisters\Entity\AbstractEntityInheritancePersister':
# method
'getSelectJoinColumnSQL':
# argument(s) to remove
- 'className'
```
- **change argument value**
```yml

View File

@ -0,0 +1,21 @@
<?php declare(strict_types=1);
namespace Rector\NodeTypeResolver\NodeVisitor;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\NodeVisitorAbstract;
final class ReturnTypeResolver extends NodeVisitorAbstract
{
public function enterNode(Node $node)
{
if (! $node instanceof MethodCall && ! $node instanceof StaticCall) {
return $node;
}
dump($node);
die;
}
}

View File

@ -96,4 +96,9 @@ final class Attribute
* @var string
*/
public const USE_NODES = 'useNodes';
/**
* @var string
*/
public const RETURN_TYPES = 'returnTypes';
}

View File

@ -186,6 +186,8 @@ final class MethodCallAnalyzer
*/
private function resolveVariableTypes(MethodCall $methodCallNode): array
{
$methodCallNode->getAttribute(Attribute::RETURN_TYPES);
$parentNode = $methodCallNode->getAttribute(Attribute::PARENT_NODE);
if ($parentNode instanceof MethodCall && $parentNode->var instanceof MethodCall) {

View File

@ -117,17 +117,9 @@ final class ArgumentReplacerRector extends AbstractRector
foreach ($this->argumentChangesMethodAndClass as $type => $argumentChangesByMethod) {
$methods = array_keys($argumentChangesByMethod);
if ($this->methodCallAnalyzer->isTypeAndMethods($node, $type, $methods)) {
if ($this->isTypeAndMethods($node, $type, $methods)) {
return $argumentChangesByMethod[$node->name->toString()];
}
// if ($this->staticMethodCallAnalyzer->isTypeAndMethods($node, $type, $methods)) {
// return $argumentChangesByMethod[$node->name->toString()];
// }
//
// if ($this->classMethodAnalyzer->isTypeAndMethods($node, $type, $methods)) {
// return $argumentChangesByMethod[$node->name->toString()];
// }
}
return null;
@ -161,4 +153,24 @@ final class ArgumentReplacerRector extends AbstractRector
$node->params = $argumentsOrParameters;
}
}
/**
* @param string[] $argumentChangesByMethod
*/
private function isTypeAndMethods(Node $node, string $type, array $methods): bool
{
if ($this->methodCallAnalyzer->isTypeAndMethods($node, $type, $methods)) {
return true;
}
if ($this->staticMethodCallAnalyzer->isTypeAndMethods($node, $type, $methods)) {
return true;
}
if ($this->classMethodAnalyzer->isTypeAndMethods($node, $type, $methods)) {
return true;
}
return false;
}
}

View File

@ -24,6 +24,8 @@ services:
- ['addNodeVisitor', ['@Rector\NodeTypeResolver\NodeVisitor\NamespaceResolver']]
# adds type to variable and property nodes via attribute
- ['addNodeVisitor', ['@Rector\NodeTypeResolver\NodeVisitor\TypeResolver']]
# adds types to method call and static call via attribute
- ['addNodeVisitor', ['@Rector\NodeTypeResolver\NodeVisitor\ReturnTypeResolver']]
# PhpParser - Parser
PhpParser\Parser: