mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-20 01:52:22 +00:00
[DeadCode] Skip fluent return $this on RemoveEmptyMethodCallRector (#521)
This commit is contained in:
parent
e5d95bda10
commit
3a96b9097d
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector\Fixture;
|
||||
|
||||
class SkipFluentReturnThis
|
||||
{
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function prepare()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
|
||||
public function call(string $class)
|
||||
{
|
||||
/** @var SkipFluentReturnThis $obj */
|
||||
$obj = new $class();
|
||||
$obj->prepare()->run();
|
||||
}
|
||||
}
|
||||
|
||||
class Extended extends SkipFluentReturnThis
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
echo 'hello';
|
||||
}
|
||||
}
|
||||
|
||||
(new SkipFluentReturnThis())->call(Extended::class);
|
||||
|
||||
?>
|
|
@ -76,7 +76,8 @@ CODE_SAMPLE
|
|||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$scope = $node->var->getAttribute(AttributeKey::SCOPE);
|
||||
$scope = $this->getScope($node);
|
||||
|
||||
if (! $scope instanceof Scope) {
|
||||
return null;
|
||||
}
|
||||
|
@ -114,6 +115,20 @@ CODE_SAMPLE
|
|||
return $node;
|
||||
}
|
||||
|
||||
private function getScope(MethodCall $methodCall): ?Scope
|
||||
{
|
||||
if ($methodCall->var instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$scope = $methodCall->var->getAttribute(AttributeKey::SCOPE);
|
||||
if (! $scope instanceof Scope) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $scope;
|
||||
}
|
||||
|
||||
private function shouldSkipClassMethod(Class_ | Trait_ | Interface_ $classLike, MethodCall $methodCall): bool
|
||||
{
|
||||
if (! $classLike instanceof Class_) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user