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
2 changes: 0 additions & 2 deletions config/set/rector-preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Class_\RemoveRefactorDuplicatedNodeInstanceCheckRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\AddSeeTestAnnotationRector;
Expand All @@ -11,7 +10,6 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
PostIncDecToPreIncDecRector::class,
FinalizeTestCaseClassRector::class,
AddParamTypeToRefactorMethodRector::class,
RemoveRefactorDuplicatedNodeInstanceCheckRector::class,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

54 changes: 8 additions & 46 deletions rules/CodingStyle/Rector/PostInc/PostIncDecToPreIncDecRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
namespace Rector\CodingStyle\Rector\PostInc;

use PhpParser\Node;
use PhpParser\Node\Expr\PostDec;
use PhpParser\Node\Expr\PostInc;
use PhpParser\Node\Expr\PreDec;
use PhpParser\Node\Expr\PreInc;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\For_;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @see \Rector\Tests\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector\PostIncDecToPreIncDecRectorTest
* @deprecated This rule is deprecated, as it is a cosmetic coding-style preference with little value. Use a coding standard tool instead.
*/
final class PostIncDecToPreIncDecRector extends AbstractRector
final class PostIncDecToPreIncDecRector extends AbstractRector implements DeprecatedInterface
{
public function getRuleDefinition(): RuleDefinition
{
Expand Down Expand Up @@ -65,45 +63,9 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node instanceof Expression) {
return $this->refactorExpression($node);
}

return $this->refactorFor($node);
}

private function refactorFor(For_ $for): For_|null
{
if (count($for->loop) !== 1) {
return null;
}

$singleLoopExpr = $for->loop[0];
if (! $singleLoopExpr instanceof PostInc && ! $singleLoopExpr instanceof PostDec) {
return null;
}

$for->loop = [$this->processPrePost($singleLoopExpr)];

return $for;
}

private function processPrePost(PostInc|PostDec $node): PreInc|PreDec
{
if ($node instanceof PostInc) {
return new PreInc($node->var);
}

return new PreDec($node->var);
}

private function refactorExpression(Expression $expression): ?Expression
{
if ($expression->expr instanceof PostInc || $expression->expr instanceof PostDec) {
$expression->expr = $this->processPrePost($expression->expr);
return $expression;
}

return null;
throw new ShouldNotHappenException(sprintf(
'"%s" rule is deprecated, as it is a cosmetic coding-style preference better handled by a coding standard tool',
self::class
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public function refactor(Node $node): int|null|array|If_
return null;
}

$conditionStaticType = $this->nodeTypeResolver->getNativeType($node->cond);
if (! $conditionStaticType->isTrue()->yes()) {
if ($this->shouldSkipExpr($node->cond)) {
return null;
}

if ($this->shouldSkipExpr($node->cond)) {
$conditionStaticType = $this->nodeTypeResolver->getNativeType($node->cond);
if (! $conditionStaticType->isTrue()->yes()) {
return null;
}

Expand Down
Loading