|
5 | 5 | namespace Rector\CodeQuality\Rector\Ternary; |
6 | 6 |
|
7 | 7 | use PhpParser\Node; |
8 | | -use PhpParser\Node\Expr; |
9 | | -use PhpParser\Node\Expr\BooleanNot; |
10 | 8 | use PhpParser\Node\Expr\Ternary; |
11 | | -use Rector\NodeTypeResolver\Node\AttributeKey; |
| 9 | +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; |
| 10 | +use Rector\Exception\ShouldNotHappenException; |
12 | 11 | use Rector\Rector\AbstractRector; |
13 | 12 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
14 | 13 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
15 | 14 |
|
16 | 15 | /** |
17 | | - * @see \Rector\Tests\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector\SwitchNegatedTernaryRectorTest |
| 16 | + * @deprecated This rule is deprecated, as it is a personal preference. Swapping the branches keeps the condition positive, but moves the values out of their logical order, e.g. a fallback value ahead of the main one. |
18 | 17 | */ |
19 | | -final class SwitchNegatedTernaryRector extends AbstractRector |
| 18 | +final class SwitchNegatedTernaryRector extends AbstractRector implements DeprecatedInterface |
20 | 19 | { |
21 | 20 | public function getRuleDefinition(): RuleDefinition |
22 | 21 | { |
@@ -65,32 +64,9 @@ public function getNodeTypes(): array |
65 | 64 | */ |
66 | 65 | public function refactor(Node $node): ?Node |
67 | 66 | { |
68 | | - if (! $node->cond instanceof BooleanNot) { |
69 | | - return null; |
70 | | - } |
71 | | - |
72 | | - if (! $node->if instanceof Expr) { |
73 | | - return null; |
74 | | - } |
75 | | - |
76 | | - $node->cond = $node->cond->expr; |
77 | | - $else = clone $node->else; |
78 | | - $if = clone $node->if; |
79 | | - |
80 | | - $node->else = $if; |
81 | | - $node->if = $else; |
82 | | - |
83 | | - if ($node->if instanceof Ternary) { |
84 | | - $ternary = $node->if; |
85 | | - $ternary->setAttribute(AttributeKey::KIND, AttributeKey::WRAPPED_IN_PARENTHESES); |
86 | | - $ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null); |
87 | | - } |
88 | | - |
89 | | - if ($node->else instanceof Ternary) { |
90 | | - $ternary = $node->else; |
91 | | - $ternary->setAttribute(AttributeKey::ORIGINAL_NODE, null); |
92 | | - } |
93 | | - |
94 | | - return $node; |
| 67 | + throw new ShouldNotHappenException(sprintf( |
| 68 | + '"%s" rule is deprecated, as it is a personal preference that can move ternary values out of their logical order', |
| 69 | + self::class |
| 70 | + )); |
95 | 71 | } |
96 | 72 | } |
0 commit comments