mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 13:13:31 +00:00
make use of isStaticCallNamed()
This commit is contained in:
parent
33e4a374d8
commit
4c4e56b168
|
@ -93,13 +93,9 @@ PHP
|
|||
return null;
|
||||
}
|
||||
|
||||
private function isAppUses($staticCall): bool
|
||||
private function isAppUses(StaticCall $staticCall): bool
|
||||
{
|
||||
if (! $this->isName($staticCall->class, 'App')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($staticCall->name, 'uses');
|
||||
return $this->isStaticCallNamed($staticCall, 'App', 'uses');
|
||||
}
|
||||
|
||||
private function createFullyQualifiedNameFromAppUsesStaticCall(StaticCall $staticCall): string
|
||||
|
|
|
@ -212,10 +212,7 @@ PHP
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($this->isName($node->expr->class, 'self')) {
|
||||
return true;
|
||||
}
|
||||
return $this->isName($node->expr->class, 'static');
|
||||
return $this->isNames($node->expr->class, ['self', 'static']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace Rector\Doctrine\Rector\Class_;
|
|||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\Type\ObjectType;
|
||||
|
@ -119,18 +118,10 @@ final class AlwaysInitializeUuidInEntityRector extends AbstractRector
|
|||
return false;
|
||||
}
|
||||
|
||||
if (! $node->expr instanceof StaticCall) {
|
||||
if (! $this->isStaticCallNamed($node->expr, 'Ramsey\Uuid\Uuid', 'uuid4')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$staticCall = $node->expr;
|
||||
if (! $this->isObjectType($staticCall->class, 'Ramsey\Uuid\Uuid')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isName($staticCall->name, 'uuid4')) {
|
||||
return false;
|
||||
}
|
||||
return $this->isName($node->var, $uuidPropertyName);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -55,11 +55,7 @@ PHP
|
|||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->class, 'ReflectionFunction')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->name, 'export')) {
|
||||
if (! $this->isStaticCallNamed($node, 'ReflectionFunction', 'export')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -357,15 +357,7 @@ PHP
|
|||
$methodStmt = $methodStmt->expr;
|
||||
}
|
||||
|
||||
if (! $methodStmt instanceof StaticCall) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $this->isName($methodStmt->class, 'parent')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $this->isName($methodStmt->name, 'setUp')) {
|
||||
if (! $this->isStaticCallNamed($methodStmt, 'parent', 'setUp')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Rector\Core\Rector\AbstractRector;
|
|||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name;
|
||||
|
@ -79,6 +80,19 @@ trait NameResolverTrait
|
|||
return $this->isName($node, $name);
|
||||
}
|
||||
|
||||
protected function isStaticCallNamed(Node $node, string $className, string $methodName): bool
|
||||
{
|
||||
if (! $node instanceof StaticCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->class, $className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($node->name, $methodName);
|
||||
}
|
||||
|
||||
protected function isMethodCall(Node $node, string $variableName, string $methodName): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall) {
|
||||
|
@ -89,7 +103,7 @@ trait NameResolverTrait
|
|||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->isName($node->name, $methodName);
|
||||
return $this->isName($node->name, $methodName);
|
||||
}
|
||||
|
||||
protected function isVariableName(?Node $node, string $name): bool
|
||||
|
|
|
@ -134,19 +134,7 @@ PHP
|
|||
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node) use (
|
||||
$method
|
||||
): bool {
|
||||
if (! $node instanceof StaticCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $node->class instanceof Name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->class, 'parent')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($node->name, $method);
|
||||
return $this->isStaticCallNamed($node, 'parent', $method);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,11 +39,7 @@ final class RemoveAnnotationRegistryRegisterFileRector extends AbstractRector im
|
|||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->class, AnnotationRegistry::class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->name, 'registerFile')) {
|
||||
if (! $this->isStaticCallNamed($node, AnnotationRegistry::class, 'registerFile')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user