[DeadCode] Fixes #4472 Remove method call on $this (#4598)

Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Abdul Malik Ikhsan 2020-11-13 18:14:25 +07:00 committed by GitHub
parent aae9a54768
commit 120e531084
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 0 deletions

View File

@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\If_;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ThisType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
@ -81,6 +82,10 @@ CODE_SAMPLE
}
$type = $scope->getType($node->var);
if ($type instanceof ThisType) {
$type = $type->getStaticObjectType();
}
if (! $type instanceof ObjectType) {
return null;
}

View File

@ -0,0 +1,34 @@
<?php
namespace Rector\DeadCode\Tests\Rector\MethodCall\RemoveEmptyMethodCallRector\Fixture;
final class GeneratorStub
{
public function __construct()
{
$this->validateLineLengths();
}
protected function validateLineLengths(): void
{
}
}
?>
-----
<?php
namespace Rector\DeadCode\Tests\Rector\MethodCall\RemoveEmptyMethodCallRector\Fixture;
final class GeneratorStub
{
public function __construct()
{
}
protected function validateLineLengths(): void
{
}
}
?>

View File

@ -0,0 +1,40 @@
<?php
namespace Rector\DeadCode\Tests\Rector\MethodCall\RemoveEmptyMethodCallRector\Fixture;
abstract class Validator
{
protected function validateLineLengths(): void
{
}
}
final class GeneratorStubUseAbstract extends Validator
{
public function __construct()
{
$this->validateLineLengths();
}
}
?>
-----
<?php
namespace Rector\DeadCode\Tests\Rector\MethodCall\RemoveEmptyMethodCallRector\Fixture;
abstract class Validator
{
protected function validateLineLengths(): void
{
}
}
final class GeneratorStubUseAbstract extends Validator
{
public function __construct()
{
}
}
?>

View File

@ -0,0 +1,22 @@
<?php
namespace Rector\DeadCode\Tests\Rector\MethodCall\RemoveEmptyMethodCallRector\Fixture;
trait ValidatorTrait
{
protected function validateLineLengths(): void
{
}
}
final class GeneratorStubUseTrait
{
use ValidatorTrait;
public function __construct()
{
$this->validateLineLengths();
}
}
?>