mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
[Defluent] Skip clone uses trait on DefluentReturnMethodCallRector (#558)
* [Defluent] Skip clone uses trait on DefluentReturnMethodCallRector
* debug
* Fixed 🎉
* phpstan
* final touch
* revert return null on parseFileNameToDecoratedNodes()
* phpstan
* phpstan
* phpstan
* phpstan
This commit is contained in:
parent
0a30f6f7ee
commit
b34ff8ca13
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\Defluent\Rector\Return_\DefluentReturnMethodCallRector\Fixture;
|
||||
|
||||
use Rector\Tests\Defluent\Rector\Return_\DefluentReturnMethodCallRector\Source\UsesTrait;
|
||||
|
||||
final class SkipCloneObjectAssignUseTrait
|
||||
{
|
||||
public function run(UsesTrait $usesTrait)
|
||||
{
|
||||
return $usesTrait->withStatus(500);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Defluent\Rector\Return_\DefluentReturnMethodCallRector\Source;
|
||||
|
||||
trait SelfButCloneAssignVersionTrait
|
||||
{
|
||||
public $status;
|
||||
|
||||
public function withStatus($status): self
|
||||
{
|
||||
$self = clone $this;
|
||||
$self->status = $status;
|
||||
|
||||
return $self;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Defluent\Rector\Return_\DefluentReturnMethodCallRector\Source;
|
||||
|
||||
class UsesTrait
|
||||
{
|
||||
use SelfButCloneAssignVersionTrait;
|
||||
}
|
|
@ -199,7 +199,13 @@ final class AstResolver
|
|||
return null;
|
||||
}
|
||||
|
||||
return $this->resolveClassMethodFromMethodReflection($methodReflection);
|
||||
$classMethod = $this->resolveClassMethodFromMethodReflection($methodReflection);
|
||||
|
||||
if (! $classMethod instanceof ClassMethod) {
|
||||
return $this->locateClassMethodInTrait($methodName, $methodReflection);
|
||||
}
|
||||
|
||||
return $classMethod;
|
||||
}
|
||||
|
||||
public function resolveClassMethodFromMethodCall(MethodCall $methodCall): ?ClassMethod
|
||||
|
@ -340,6 +346,21 @@ final class AstResolver
|
|||
return $this->findPromotedPropertyByName($nodes, $desiredPropertyName);
|
||||
}
|
||||
|
||||
private function locateClassMethodInTrait(string $methodName, MethodReflection $methodReflection): ?ClassMethod
|
||||
{
|
||||
$classReflection = $methodReflection->getDeclaringClass();
|
||||
$traits = $this->parseClassReflectionTraits($classReflection);
|
||||
|
||||
/** @var ClassMethod|null $classMethod */
|
||||
$classMethod = $this->betterNodeFinder->findFirst(
|
||||
$traits,
|
||||
fn (Node $node): bool => $node instanceof ClassMethod && $this->nodeNameResolver->isName($node, $methodName)
|
||||
);
|
||||
$this->classMethodsByClassAndMethod[$classReflection->getName()][$methodName] = $classMethod;
|
||||
|
||||
return $classMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Stmt[]|null
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user