diff --git a/README.md b/README.md index be44e40c652..12dd1d728c4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/packages/NodeTypeResolver/src/NodeVisitor/ReturnTypeResolver.php b/packages/NodeTypeResolver/src/NodeVisitor/ReturnTypeResolver.php new file mode 100644 index 00000000000..7b517eedd4b --- /dev/null +++ b/packages/NodeTypeResolver/src/NodeVisitor/ReturnTypeResolver.php @@ -0,0 +1,21 @@ +getAttribute(Attribute::RETURN_TYPES); + $parentNode = $methodCallNode->getAttribute(Attribute::PARENT_NODE); if ($parentNode instanceof MethodCall && $parentNode->var instanceof MethodCall) { diff --git a/src/Rector/Dynamic/ArgumentReplacerRector.php b/src/Rector/Dynamic/ArgumentReplacerRector.php index db751781efd..4db883da01e 100644 --- a/src/Rector/Dynamic/ArgumentReplacerRector.php +++ b/src/Rector/Dynamic/ArgumentReplacerRector.php @@ -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; + } } diff --git a/src/config/services.yml b/src/config/services.yml index 5755a31dfdc..1fda6b0284e 100644 --- a/src/config/services.yml +++ b/src/config/services.yml @@ -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: