Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@
namespace Rector\CodeQuality\Rector\Expression;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use Rector\NodeAnalyzer\ExprAnalyzer;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\CodeSample;
use Rector\RuleDoc\RuleDefinition;

/**
* @see \Rector\Tests\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector\TernaryFalseExpressionToIfRectorTest
* @deprecated This rule is deprecated, as too niche for wide application.
*/
final class TernaryFalseExpressionToIfRector extends AbstractRector
final class TernaryFalseExpressionToIfRector extends AbstractRector implements DeprecatedInterface
{
public function __construct(
private readonly ExprAnalyzer $exprAnalyzer
) {
}

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Change ternary with false to if and explicit call', [
Expand Down Expand Up @@ -68,25 +60,6 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($this->getFile()->containsHTML()) {
return null;
}

if (! $node->expr instanceof Ternary) {
return null;
}

$ternary = $node->expr;
if (! $ternary->if instanceof Expr) {
return null;
}

if (! $ternary->else instanceof Variable && $this->exprAnalyzer->isDynamicExpr($ternary->else)) {
return null;
}

return new If_($ternary->cond, [
'stmts' => [new Expression($ternary->if)],
]);
throw new ShouldNotHappenException(sprintf('"%s" rule is deprecated, as too niche for wide application', self::class));
}
}
2 changes: 0 additions & 2 deletions src/Config/Level/CodeQualityLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector;
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
use Rector\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector;
use Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector;
use Rector\CodeQuality\Rector\Foreach_\SimplifyForeachToCoalescingRector;
use Rector\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector;
Expand Down Expand Up @@ -146,7 +145,6 @@ final class CodeQualityLevel
VariableConstFetchToClassConstFetchRector::class,
SingularSwitchToIfRector::class,
InlineIfToExplicitIfRector::class,
TernaryFalseExpressionToIfRector::class,
SimplifyIfNullableReturnRector::class,
InlineArrayReturnAssignRector::class,
RemoveAlwaysElseRector::class,
Expand Down
3 changes: 1 addition & 2 deletions tests/Issues/ChangeSwitchTernary/config/configured_rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector;
use Rector\Config\RectorConfig;
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
use Rector\Tests\Issues\ChangeSwitchTernary\Source\AnotherExpressionRector;

return RectorConfig::configure()
->withRules(
[ChangeSwitchToMatchRector::class, TernaryFalseExpressionToIfRector::class, AnotherExpressionRector::class]
[ChangeSwitchToMatchRector::class, AnotherExpressionRector::class]
);
Loading