|
5 | 5 | namespace Rector\CodingStyle\Rector\PostInc; |
6 | 6 |
|
7 | 7 | use PhpParser\Node; |
8 | | -use PhpParser\Node\Expr\PostDec; |
9 | | -use PhpParser\Node\Expr\PostInc; |
10 | | -use PhpParser\Node\Expr\PreDec; |
11 | | -use PhpParser\Node\Expr\PreInc; |
12 | 8 | use PhpParser\Node\Stmt\Expression; |
13 | 9 | use PhpParser\Node\Stmt\For_; |
| 10 | +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; |
| 11 | +use Rector\Exception\ShouldNotHappenException; |
14 | 12 | use Rector\Rector\AbstractRector; |
15 | 13 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
16 | 14 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
17 | 15 |
|
18 | 16 | /** |
19 | | - * @see \Rector\Tests\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector\PostIncDecToPreIncDecRectorTest |
| 17 | + * @deprecated This rule is deprecated, as it is a cosmetic coding-style preference with little value. Use a coding standard tool instead. |
20 | 18 | */ |
21 | | -final class PostIncDecToPreIncDecRector extends AbstractRector |
| 19 | +final class PostIncDecToPreIncDecRector extends AbstractRector implements DeprecatedInterface |
22 | 20 | { |
23 | 21 | public function getRuleDefinition(): RuleDefinition |
24 | 22 | { |
@@ -65,45 +63,9 @@ public function getNodeTypes(): array |
65 | 63 | */ |
66 | 64 | public function refactor(Node $node): ?Node |
67 | 65 | { |
68 | | - if ($node instanceof Expression) { |
69 | | - return $this->refactorExpression($node); |
70 | | - } |
71 | | - |
72 | | - return $this->refactorFor($node); |
73 | | - } |
74 | | - |
75 | | - private function refactorFor(For_ $for): For_|null |
76 | | - { |
77 | | - if (count($for->loop) !== 1) { |
78 | | - return null; |
79 | | - } |
80 | | - |
81 | | - $singleLoopExpr = $for->loop[0]; |
82 | | - if (! $singleLoopExpr instanceof PostInc && ! $singleLoopExpr instanceof PostDec) { |
83 | | - return null; |
84 | | - } |
85 | | - |
86 | | - $for->loop = [$this->processPrePost($singleLoopExpr)]; |
87 | | - |
88 | | - return $for; |
89 | | - } |
90 | | - |
91 | | - private function processPrePost(PostInc|PostDec $node): PreInc|PreDec |
92 | | - { |
93 | | - if ($node instanceof PostInc) { |
94 | | - return new PreInc($node->var); |
95 | | - } |
96 | | - |
97 | | - return new PreDec($node->var); |
98 | | - } |
99 | | - |
100 | | - private function refactorExpression(Expression $expression): ?Expression |
101 | | - { |
102 | | - if ($expression->expr instanceof PostInc || $expression->expr instanceof PostDec) { |
103 | | - $expression->expr = $this->processPrePost($expression->expr); |
104 | | - return $expression; |
105 | | - } |
106 | | - |
107 | | - return null; |
| 66 | + throw new ShouldNotHappenException(sprintf( |
| 67 | + '"%s" rule is deprecated, as it is a cosmetic coding-style preference better handled by a coding standard tool', |
| 68 | + self::class |
| 69 | + )); |
108 | 70 | } |
109 | 71 | } |
0 commit comments