Skip to content

Commit

Permalink
[DowngradePhp80] Skip remove self on DowngradeStaticTypeDeclarationRe…
Browse files Browse the repository at this point in the history
…ctor (#721)

Co-authored-by: Brandon Olivares <programmer2188@gmail.com>
  • Loading branch information
samsonasik and devbanana committed Aug 20, 2021
1 parent 998029d commit 3c8f8a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -72,6 +73,13 @@ public function getStatic()
*/
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);
Expand Down

0 comments on commit 3c8f8a0

Please sign in to comment.