diff --git a/rules-tests/Strict/Rector/Ternary/DisallowedShortTernaryRuleFixerRector/Fixture/skip_docblock.php.inc b/rules-tests/Strict/Rector/Ternary/DisallowedShortTernaryRuleFixerRector/Fixture/skip_docblock.php.inc new file mode 100644 index 00000000000..3bd7c6889b8 --- /dev/null +++ b/rules-tests/Strict/Rector/Ternary/DisallowedShortTernaryRuleFixerRector/Fixture/skip_docblock.php.inc @@ -0,0 +1,16 @@ +hasChanged = false; + // skip non-short ternary if ($node->if instanceof Expr) { return null; @@ -83,10 +87,15 @@ public function refactorWithScope(Node $node, Scope $scope): ?Ternary // special case for reset() function if ($node->cond instanceof FuncCall && $this->isName($node->cond, 'reset')) { $this->refactorResetFuncCall($node, $node->cond, $scope); + + if (! $this->hasChanged) { + return null; + } + return $node; } - $exprType = $scope->getType($node->cond); + $exprType = $scope->getNativeType($node->cond); $compareExpr = $this->exactCompareFactory->createNotIdenticalFalsyCompare( $exprType, $node->cond, @@ -112,7 +121,7 @@ private function refactorResetFuncCall(Ternary $ternary, FuncCall $resetFuncCall $firstArgValue = $resetFuncCall->getArgs()[0] ->value; - $firstArgType = $scope->getType($firstArgValue); + $firstArgType = $scope->getNativeType($firstArgValue); $falsyCompareExpr = $this->exactCompareFactory->createNotIdenticalFalsyCompare( $firstArgType, @@ -125,5 +134,6 @@ private function refactorResetFuncCall(Ternary $ternary, FuncCall $resetFuncCall } $ternary->cond = $falsyCompareExpr; + $this->hasChanged = true; } }