diff --git a/rules/php-72/src/Rector/FuncCall/GetClassOnNullRector.php b/rules/php-72/src/Rector/FuncCall/GetClassOnNullRector.php index 5dfe0070da36..fdc16da31206 100644 --- a/rules/php-72/src/Rector/FuncCall/GetClassOnNullRector.php +++ b/rules/php-72/src/Rector/FuncCall/GetClassOnNullRector.php @@ -12,6 +12,7 @@ use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\Stmt\Trait_; use PHPStan\Analyser\Scope; use PHPStan\Type\NullType; use Rector\Core\Rector\AbstractRector; @@ -107,6 +108,11 @@ public function refactor(Node $node): ?Node private function shouldSkip(FuncCall $funcCall): bool { + $class = $funcCall->getAttribute(AttributeKey::CLASS_NODE); + if ($class instanceof Trait_) { + return true; + } + $parentNode = $funcCall->getAttribute(AttributeKey::PARENT_NODE); if (! $parentNode instanceof Ternary) { return false; @@ -115,7 +121,12 @@ private function shouldSkip(FuncCall $funcCall): bool if ($this->isIdenticalToNotNull($funcCall, $parentNode)) { return true; } - return $this->isNotIdenticalToNull($funcCall, $parentNode); + + if ($this->isNotIdenticalToNull($funcCall, $parentNode)) { + return true; + } + + return false; } /**