mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 04:19:44 +01:00
skip call() based conventions
This commit is contained in:
parent
8b831a75b8
commit
af6d35dc4d
@ -161,20 +161,17 @@ final class ExpectedNameResolver
|
||||
return $this->propertyNaming->getExpectedNameFromType($fullyQualifiedObjectType);
|
||||
}
|
||||
|
||||
public function resolveForGetCallExpr(Expr $expr): ?string
|
||||
/**
|
||||
* @param MethodCall|StaticCall|FuncCall $call
|
||||
*/
|
||||
public function resolveForGetCallExpr(Expr $call): ?string
|
||||
{
|
||||
if (! $expr instanceof MethodCall && ! $expr instanceof StaticCall && ! $expr instanceof FuncCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$name = $this->nodeNameResolver->getName($expr->name);
|
||||
$name = $this->nodeNameResolver->getName($call->name);
|
||||
if ($name === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// dump($expr);
|
||||
|
||||
$returnedType = $this->nodeTypeResolver->getStaticType($expr);
|
||||
$returnedType = $this->nodeTypeResolver->getStaticType($call);
|
||||
if ($returnedType instanceof MixedType) {
|
||||
return null;
|
||||
}
|
||||
|
@ -5,9 +5,11 @@ declare(strict_types=1);
|
||||
namespace Rector\Naming\Rector\Assign;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Param;
|
||||
@ -93,7 +95,11 @@ PHP
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if ($node->expr instanceof ArrowFunction || ! $node->var instanceof Variable) {
|
||||
if (! $node->expr instanceof MethodCall && ! $node->expr instanceof StaticCall && ! $node->expr instanceof FuncCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $node->var instanceof Variable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -107,6 +113,12 @@ PHP
|
||||
return null;
|
||||
}
|
||||
|
||||
// skip "$call = $method->call();" based conventions
|
||||
$callName = $this->getName($node->expr->name);
|
||||
if ($currentName === $callName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$functionLike = $this->getCurrentFunctionLike($node);
|
||||
if ($functionLike === null) {
|
||||
return null;
|
||||
|
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Naming\Tests\Rector\Assign\RenameVariableToMatchGetMethodNameRector\Fixture;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
class SkipMethodNameBasedConvention
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$containerConfigurator = new ContainerConfigurator();
|
||||
$services = $containerConfigurator->services();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user