Skip to content

Commit

Permalink
[CodeQuality] Skip parent::class usage on GetClassToInstanceOfRector (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik authored Apr 2, 2022
1 parent 7a37df2 commit 3b40197
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Identical\GetClassToInstanceOfRector\Fixture;

class SkipParentUsage extends SomeParent {
public function test(object $other) {
var_dump(parent::class);
var_dump(get_class($other) === parent::class);
var_dump($other instanceof parent);
}
}

(new SkipParentUsage())->test(new SkipParentUsage());
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Identical\GetClassToInstanceOfRector\Source;

class SomeParent
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\String_;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\NodeManipulator\BinaryOpManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Php71\ValueObject\TwoNodeMatch;
Expand Down Expand Up @@ -98,6 +99,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($className === ObjectReference::PARENT()->getValue()) {
return null;
}

$class = in_array($className, self::NO_NAMESPACED_CLASSNAMES, true)
? new Name($className)
: new FullyQualified($className);
Expand Down

0 comments on commit 3b40197

Please sign in to comment.