From 935b08e4ad6a4152a386d0d3c1203623009927b5 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 29 Feb 2020 02:10:30 +0100 Subject: [PATCH] fix get class on trait --- .../src/Rector/FuncCall/GetClassOnNullRector.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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; } /**