[DowngradePhp80] Skip remove self on DowngradeStaticTypeDeclarationRector (#721)

Co-authored-by: Brandon Olivares <programmer2188@gmail.com>
This commit is contained in:
Abdul Malik Ikhsan 2021-08-20 17:27:45 +07:00 committed by GitHub
parent 998029d4fc
commit 3c8f8a03d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Rector\Tests\DowngradePhp80\Rector\ClassMethod\DowngradeStaticTypeDeclarationRector\Fixture;
final class SkipSelf
{
public function run(): self
{
return $this;
}
}

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\DowngradePhp80\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
@ -72,6 +73,13 @@ CODE_SAMPLE
*/
public function refactor(Node $node): ?Node
{
if ($node->returnType instanceof Name && $this->nodeNameResolver->isName(
$node->returnType,
'self'
)) {
return null;
}
$scope = $node->getAttribute(AttributeKey::SCOPE);
if ($scope === null) {
$className = $node->getAttribute(AttributeKey::CLASS_NAME);