mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
cleanup
This commit is contained in:
parent
7f9e1a3497
commit
bfc26a9e5b
13
README.md
13
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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -96,4 +96,9 @@ final class Attribute
|
||||
* @var string
|
||||
*/
|
||||
public const USE_NODES = 'useNodes';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RETURN_TYPES = 'returnTypes';
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user