diff --git a/config/set/if.php b/config/set/if.php index 25bed6fd98d..2faf066c142 100644 --- a/config/set/if.php +++ b/config/set/if.php @@ -2,29 +2,9 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; -use Rector\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector; -use Rector\CodeQuality\Rector\If_\ArrayExplicitBoolCompareRector; -use Rector\CodeQuality\Rector\If_\CombineIfRector; -use Rector\CodeQuality\Rector\If_\CompleteMissingIfElseBracketRector; -use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; -use Rector\CodeQuality\Rector\If_\ObjectExplicitBoolCompareRector; -use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; -use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; -use Rector\CodingStyle\Rector\If_\AlternativeIfToBracketRector; use Rector\Config\RectorConfig; +// note: all if rules were moved to code quality and coding style sets, or deprecated return static function (RectorConfig $rectorConfig): void { - $rectorConfig->rules([ - AlternativeIfToBracketRector::class, - CompleteMissingIfElseBracketRector::class, - InlineIfToExplicitIfRector::class, - TernaryFalseExpressionToIfRector::class, - ArrayExplicitBoolCompareRector::class, - ObjectExplicitBoolCompareRector::class, - ExplicitBoolCompareRector::class, - CombineIfRector::class, - ShortenElseIfRector::class, - SimplifyIfElseToTernaryRector::class, - ]); + $rectorConfig->rules([]); }; diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/CombineIfRectorTest.php b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/CombineIfRectorTest.php deleted file mode 100644 index eee478ed119..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/CombineIfRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/docblock.php.inc b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/docblock.php.inc deleted file mode 100644 index f48889279e1..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/docblock.php.inc +++ /dev/null @@ -1,51 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/fixture.php.inc b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/fixture.php.inc deleted file mode 100644 index 36c4568c8bd..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,33 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/property_fetch_in_condition.php.inc b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/property_fetch_in_condition.php.inc deleted file mode 100644 index d71f39ff905..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/property_fetch_in_condition.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -art->netzid > 0 && $artzo_list = $this->artzo_list) { - if ($artzo_list !== []) { - foreach ($artzo_list as $art) { - } - } - } - } -} -?> ------ -art->netzid > 0 && ($artzo_list = $this->artzo_list) && $artzo_list !== []) { - foreach ($artzo_list as $art) { - } - } - } -} -?> diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/property_fetch_in_condition2.php.inc b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/property_fetch_in_condition2.php.inc deleted file mode 100644 index f7b54d84f66..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/property_fetch_in_condition2.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -art->netzid > 0 && $artzo_list = $this->artzo_list) { - foreach ($artzo_list as $art) { - } - } - } - } -} -?> ------ -art->netzid > 0 && $artzo_list = $this->artzo_list)) { - foreach ($artzo_list as $art) { - } - } - } -} -?> diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_child_else.php.inc b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_child_else.php.inc deleted file mode 100644 index 800101e9466..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_child_else.php.inc +++ /dev/null @@ -1,17 +0,0 @@ - diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_nested_type.php.inc b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_nested_type.php.inc deleted file mode 100644 index 8c7ada706da..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_nested_type.php.inc +++ /dev/null @@ -1,29 +0,0 @@ -isAssign($expr)) { - /** @var Assign $expr */ - if ($expr->var) { - return true; - } - } - - return false; - } - - private function isAssign($expr) - { - if ($expr instanceof Assign) { - return true; - } - - return false; - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_parent_else.php.inc b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_parent_else.php.inc deleted file mode 100644 index 0220ad6ee04..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/skip_parent_else.php.inc +++ /dev/null @@ -1,17 +0,0 @@ -getCond2Value()) === null) { - return 'foo'; - } - } - } -} - -?> ------ -getCond2Value()) === null) { - return 'foo'; - } - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/with_negation_binaryop_previous_if.php.inc b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/with_negation_binaryop_previous_if.php.inc deleted file mode 100644 index 920b5b7795a..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/Fixture/with_negation_binaryop_previous_if.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/If_/CombineIfRector/config/configured_rule.php deleted file mode 100644 index 0357f4362ca..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/CombineIfRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([CombineIfRector::class]); diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/ExplicitBoolCompareRectorTest.php b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/ExplicitBoolCompareRectorTest.php deleted file mode 100644 index eb5c4fa1ec0..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/ExplicitBoolCompareRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/count.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/count.php.inc deleted file mode 100644 index 41747710a38..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/count.php.inc +++ /dev/null @@ -1,35 +0,0 @@ - ------ - 0) { - return 'many items'; - } - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/explode.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/explode.php.inc deleted file mode 100644 index 4291877dbed..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/explode.php.inc +++ /dev/null @@ -1,37 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/if_assign_cond.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/if_assign_cond.php.inc deleted file mode 100644 index 21fe987bf2f..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/if_assign_cond.php.inc +++ /dev/null @@ -1,36 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/numbers.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/numbers.php.inc deleted file mode 100644 index 39c8cc5c52f..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/numbers.php.inc +++ /dev/null @@ -1,53 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/phpstan_0_12_6break.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/phpstan_0_12_6break.php.inc deleted file mode 100644 index 05bf39096d7..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/phpstan_0_12_6break.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_if_else.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_if_else.php.inc deleted file mode 100644 index a533a32c5a7..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_if_else.php.inc +++ /dev/null @@ -1,17 +0,0 @@ -elseifs) { - return true; - } - - return false; - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_nested_array_mixed.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_nested_array_mixed.php.inc deleted file mode 100644 index 9b70d670e89..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_nested_array_mixed.php.inc +++ /dev/null @@ -1,17 +0,0 @@ -provider(); - $this->value = $data['key'] ? 1 : 2; - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_phpdoc-typed.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_phpdoc-typed.php.inc deleted file mode 100644 index 293a0f3d70f..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/skip_phpdoc-typed.php.inc +++ /dev/null @@ -1,26 +0,0 @@ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string.php.inc deleted file mode 100644 index 34ab2ba5fe4..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string.php.inc +++ /dev/null @@ -1,39 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value.php.inc deleted file mode 100644 index b59f134198a..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value.php.inc +++ /dev/null @@ -1,53 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value2.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value2.php.inc deleted file mode 100644 index 951eb4714ca..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value2.php.inc +++ /dev/null @@ -1,53 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value3.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value3.php.inc deleted file mode 100644 index a9fdd29db99..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/string_known_value3.php.inc +++ /dev/null @@ -1,53 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/with_ternary.php.inc b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/with_ternary.php.inc deleted file mode 100644 index 5a1ff5d8630..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/Fixture/with_ternary.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/config/configured_rule.php deleted file mode 100644 index b33ccbcbfcf..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/ExplicitBoolCompareRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([ExplicitBoolCompareRector::class]); diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/fixture.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/fixture.php.inc deleted file mode 100644 index aaa38954dbe..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -arrayBuilt[][$key] = true; - } else { - $this->arrayBuilt[][$key] = $value; - } - } -} - -?> ------ -arrayBuilt[][$key] = empty($value) ? true : $value; - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/keep.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/keep.php.inc deleted file mode 100644 index 4a57ed9655a..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/keep.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -arrayBuilt[][$key] = true; - } else { - $this->arrayBuilt[][$key2] = $value; - } - - if (empty($value)) { - $this->arrayBuilt[][$key] = true; - } elseif (!empty($value)) { - $this->arrayBuilt[][$key] = $value; - } - - if (empty($value)) { - $this->arrayBuilt[][$key] = true; - } elseif (!empty($value)) { - $this->arrayBuilt[][$key] = $value; - } - - if (empty($value)) { - $name = true; - } else { - $surname = $value; - } - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/keep_nested_ternary.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/keep_nested_ternary.php.inc deleted file mode 100644 index a7c82da8bbd..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/keep_nested_ternary.php.inc +++ /dev/null @@ -1,21 +0,0 @@ -typeAnalyzer->isPhpReservedType($type) ? $type : '\\' . $type; - } else { - $type = (string) $type; - } - - if ($type ? true : false) { - $type = 'Hou'; - } else { - $type = (string) $type; - } - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/mirror_comment.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/mirror_comment.php.inc deleted file mode 100644 index 4c7ef292159..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/mirror_comment.php.inc +++ /dev/null @@ -1,33 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/operator_precedence.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/operator_precedence.php.inc deleted file mode 100644 index 0aa82d52ea6..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/operator_precedence.php.inc +++ /dev/null @@ -1,37 +0,0 @@ - ------ - diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/skip_too_long.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/skip_too_long.php.inc deleted file mode 100644 index df4d5edebed..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/skip_too_long.php.inc +++ /dev/null @@ -1,18 +0,0 @@ -nodeTypeResolver->isStringyType($staticCall->args[1]->value)) { - $name = $this->nameResolver->isName( - $staticCall, - 'contains' - ) ? 'assertStringContainsString' : 'assertStringNotContainsString'; - } else { - $name = $this->nameResolver->isName($staticCall, 'contains') ? 'assertContains' : 'assertNotContains'; - } - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/skip_with_comment_inside.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/skip_with_comment_inside.php.inc deleted file mode 100644 index 93458b1a3e2..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/skip_with_comment_inside.php.inc +++ /dev/null @@ -1,17 +0,0 @@ -toRawArray(); - } else { - $properties = (array) $data; - } - - return $properties; - } -} - -?> ------ -toRawArray() : (array) $data; - - return $properties; - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/with_assign.php.inc b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/with_assign.php.inc deleted file mode 100644 index 91e2cbf49c2..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture/with_assign.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -methodX()) { - $this->out = $a; - } else { - $this->out = $this->methodY(); - } - } -} - -?> ------ -out = ($a = $this->methodX()) ? $a : $this->methodY(); - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/SimplifyIfElseToTernaryRectorTest.php b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/SimplifyIfElseToTernaryRectorTest.php deleted file mode 100644 index e488ebb2b31..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/SimplifyIfElseToTernaryRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/config/configured_rule.php deleted file mode 100644 index eba00b24ee1..00000000000 --- a/rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([SimplifyIfElseToTernaryRector::class]); diff --git a/rules/CodeQuality/Rector/If_/CombineIfRector.php b/rules/CodeQuality/Rector/If_/CombineIfRector.php index b3e13d6f28c..6609a713e2c 100644 --- a/rules/CodeQuality/Rector/If_/CombineIfRector.php +++ b/rules/CodeQuality/Rector/If_/CombineIfRector.php @@ -5,31 +5,18 @@ namespace Rector\CodeQuality\Rector\If_; use PhpParser\Node; -use PhpParser\Node\Expr\BinaryOp; -use PhpParser\Node\Expr\BinaryOp\BooleanAnd; -use PhpParser\Node\Expr\BooleanNot; -use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\If_; -use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; -use Rector\BetterPhpDocParser\Comment\CommentsMerger; -use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; -use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; -use Rector\NodeTypeResolver\Node\AttributeKey; +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\CodeQuality\Rector\If_\CombineIfRector\CombineIfRectorTest + * @deprecated This rule is deprecated, as merging nested ifs can create much less readable code and depends on context. */ -final class CombineIfRector extends AbstractRector +final class CombineIfRector extends AbstractRector implements DeprecatedInterface { - public function __construct( - private readonly CommentsMerger $commentsMerger, - private readonly PhpDocInfoFactory $phpDocInfoFactory - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Merge nested if statements', [ @@ -76,78 +63,9 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if ($this->shouldSkip($node)) { - return null; - } - - /** @var If_ $subIf */ - $subIf = $node->stmts[0]; - - if ($this->hasVarTag($subIf)) { - return null; - } - - $node->cond->setAttribute(AttributeKey::ORIGINAL_NODE, null); - - $cond = $node->cond; - - while ($cond instanceof BinaryOp) { - if (! $cond->right instanceof BinaryOp) { - $cond->right->setAttribute(AttributeKey::ORIGINAL_NODE, null); - } - - $cond = $cond->right; - } - - if ($subIf->cond instanceof BinaryOp && ! $subIf->cond->left instanceof BinaryOp) { - $subIf->cond->left->setAttribute(AttributeKey::ORIGINAL_NODE, null); - } - - if ($node->cond instanceof BooleanNot && $node->cond->expr instanceof BinaryOp) { - $node->cond->expr->setAttribute(AttributeKey::ORIGINAL_NODE, null); - } - - $node->cond = new BooleanAnd($node->cond, $subIf->cond); - - $node->stmts = $subIf->stmts; - - $this->commentsMerger->keepComments($node, [$subIf]); - - return $node; - } - - private function shouldSkip(If_ $if): bool - { - if ($if->else instanceof Else_) { - return true; - } - - if (count($if->stmts) !== 1) { - return true; - } - - if ($if->elseifs !== []) { - return true; - } - - if (! $if->stmts[0] instanceof If_) { - return true; - } - - if ($if->stmts[0]->else instanceof Else_) { - return true; - } - - return (bool) $if->stmts[0]->elseifs; - } - - private function hasVarTag(If_ $if): bool - { - $subIfPhpDocInfo = $this->phpDocInfoFactory->createFromNode($if); - if (! $subIfPhpDocInfo instanceof PhpDocInfo) { - return false; - } - - return $subIfPhpDocInfo->getVarTagValueNode() instanceof VarTagValueNode; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as merging nested ifs can create much less readable code and depends on context', + self::class + )); } } diff --git a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php index 58b33b1933d..b1215030288 100644 --- a/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php +++ b/rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php @@ -5,46 +5,20 @@ namespace Rector\CodeQuality\Rector\If_; use PhpParser\Node; -use PhpParser\Node\Expr; -use PhpParser\Node\Expr\Assign; -use PhpParser\Node\Expr\BinaryOp; -use PhpParser\Node\Expr\BinaryOp\BooleanAnd; -use PhpParser\Node\Expr\BinaryOp\BooleanOr; -use PhpParser\Node\Expr\BinaryOp\Greater; -use PhpParser\Node\Expr\BinaryOp\Identical; -use PhpParser\Node\Expr\BinaryOp\NotIdentical; -use PhpParser\Node\Expr\BooleanNot; -use PhpParser\Node\Expr\Cast\Bool_; -use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Ternary; -use PhpParser\Node\Scalar\Float_; -use PhpParser\Node\Scalar\Int_; -use PhpParser\Node\Scalar\String_; -use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ElseIf_; -use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; -use PHPStan\Type\MixedType; -use PHPStan\Type\ObjectType; -use Rector\NodeTypeResolver\TypeAnalyzer\ArrayTypeAnalyzer; -use Rector\NodeTypeResolver\TypeAnalyzer\StringTypeAnalyzer; -use Rector\PhpParser\Node\Value\ValueResolver; +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\CodeQuality\Rector\If_\ExplicitBoolCompareRector\ExplicitBoolCompareRectorTest + * @deprecated This rule is deprecated. Array and object bool compares have dedicated rules; the rest is an opinionated approach that depends on context. */ -final class ExplicitBoolCompareRector extends AbstractRector +final class ExplicitBoolCompareRector extends AbstractRector implements DeprecatedInterface { - public function __construct( - private readonly StringTypeAnalyzer $stringTypeAnalyzer, - private readonly ArrayTypeAnalyzer $arrayTypeAnalyzer, - private readonly ValueResolver $valueResolver, - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Make if conditions more explicit', [ @@ -86,174 +60,12 @@ public function getNodeTypes(): array /** * @param If_|ElseIf_|Ternary $node - * @return null|Stmt[]|Node */ - public function refactor(Node $node): null|array|Node + public function refactor(Node $node): ?Node { - // skip short ternary - if ($node instanceof Ternary && ! $node->if instanceof Expr) { - return null; - } - - if ($node->cond instanceof BooleanNot) { - $conditionNode = $node->cond->expr; - $isNegated = true; - } else { - $conditionNode = $node->cond; - $isNegated = false; - } - - if ($conditionNode instanceof Bool_) { - return null; - } - - $conditionStaticType = $this->nodeTypeResolver->getNativeType($conditionNode); - if ($conditionStaticType instanceof MixedType || $conditionStaticType->isBoolean()->yes()) { - return null; - } - - // handled by ArrayExplicitBoolCompareRector - if ($this->arrayTypeAnalyzer->isArrayType($conditionNode)) { - return null; - } - - // handled by ObjectExplicitBoolCompareRector - if ($this->nodeTypeResolver->matchNullableTypeOfSpecificType( - $conditionNode, - ObjectType::class - ) instanceof ObjectType) { - return null; - } - - $binaryOp = $this->resolveNewConditionNode($conditionNode, $isNegated); - if (! $binaryOp instanceof Expr) { - return null; - } - - if ($node instanceof If_ && $node->cond instanceof Assign && $binaryOp->left instanceof NotIdentical && $binaryOp->right instanceof NotIdentical) { - $expression = new Expression($node->cond); - $binaryOp->left->left = $node->cond->var; - $binaryOp->right->left = $node->cond->var; - - $node->cond = $binaryOp; - - return [$expression, $node]; - } - - $node->cond = $binaryOp; - - return $node; - } - - private function resolveNewConditionNode(Expr $expr, bool $isNegated): ?BinaryOp - { - if ($expr instanceof FuncCall && $this->isName($expr, 'count')) { - return $this->resolveCount($isNegated, $expr); - } - - if ($this->stringTypeAnalyzer->isStringOrUnionStringOnlyType($expr)) { - return $this->resolveString($isNegated, $expr); - } - - $exprType = $this->getType($expr); - if ($exprType->isInteger()->yes()) { - return $this->resolveInteger($isNegated, $expr); - } - - if ($exprType->isFloat()->yes()) { - return $this->resolveFloat($isNegated, $expr); - } - - return null; - } - - private function resolveCount(bool $isNegated, FuncCall $funcCall): Identical|Greater|null - { - if ($funcCall->isFirstClassCallable()) { - return null; - } - - $countedType = $this->getType($funcCall->getArgs()[0]->value); - - if ($countedType->isArray()->yes()) { - return null; - } - - $int = new Int_(0); - - // compare === 0, assumption - if ($isNegated) { - return new Identical($funcCall, $int); - } - - return new Greater($funcCall, $int); - } - - private function resolveString(bool $isNegated, Expr $expr): Identical|NotIdentical|BooleanAnd|BooleanOr - { - $emptyString = new String_(''); - - $identical = $this->resolveIdentical($expr, $isNegated, $emptyString); - - $value = $this->valueResolver->getValue($expr); - - // unknown value. may be from parameter - if ($value === null) { - return $this->resolveZeroIdenticalString($identical, $isNegated, $expr); - } - - $length = strlen((string) $value); - - if ($length === 1) { - $zeroString = new String_('0'); - return $this->resolveIdentical($expr, $isNegated, $zeroString); - } - - return $identical; - } - - private function resolveIdentical(Expr $expr, bool $isNegated, String_ $string): Identical|NotIdentical - { - /** - * // compare === '' - */ - $identical = $isNegated - ? new Identical($expr, $string) - : new NotIdentical($expr, $string); - - return $identical; - } - - private function resolveZeroIdenticalString( - Identical|NotIdentical $identical, - bool $isNegated, - Expr $expr - ): BooleanAnd|BooleanOr { - $string = new String_('0'); - - $zeroIdentical = $isNegated ? new Identical($expr, $string) : new NotIdentical($expr, $string); - return $isNegated ? new BooleanOr($identical, $zeroIdentical) : new BooleanAnd($identical, $zeroIdentical); - } - - private function resolveInteger(bool $isNegated, Expr $expr): Identical|NotIdentical - { - $int = new Int_(0); - - if ($isNegated) { - return new Identical($expr, $int); - } - - return new NotIdentical($expr, $int); - } - - private function resolveFloat(bool $isNegated, Expr $expr): Identical|NotIdentical - { - $float = new Float_(0.0); - - if ($isNegated) { - return new Identical($expr, $float); - } - - return new NotIdentical($expr, $float); + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as array and object bool compares have dedicated rules and the rest is an opinionated approach that depends on context', + self::class + )); } } diff --git a/rules/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector.php b/rules/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector.php index 808ac5d7136..cd2292e7440 100644 --- a/rules/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector.php +++ b/rules/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector.php @@ -5,34 +5,18 @@ namespace Rector\CodeQuality\Rector\If_; use PhpParser\Node; -use PhpParser\Node\Expr; -use PhpParser\Node\Expr\Assign; -use PhpParser\Node\Expr\BinaryOp; -use PhpParser\Node\Expr\Ternary; -use PhpParser\Node\Stmt; -use PhpParser\Node\Stmt\Else_; -use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; -use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\PhpParser\Node\BetterNodeFinder; -use Rector\PhpParser\Printer\BetterStandardPrinter; +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\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector\SimplifyIfElseToTernaryRectorTest + * @deprecated This rule is deprecated, as the result depends on context and can worsen readability. Extract a method instead if needed. */ -final class SimplifyIfElseToTernaryRector extends AbstractRector +final class SimplifyIfElseToTernaryRector extends AbstractRector implements DeprecatedInterface { - private const int LINE_LENGTH_LIMIT = 120; - - public function __construct( - private readonly BetterStandardPrinter $betterStandardPrinter, - private readonly BetterNodeFinder $betterNodeFinder - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -80,127 +64,9 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $node->else instanceof Else_) { - return null; - } - - if ($node->elseifs !== []) { - return null; - } - - $ifAssignVarExpr = $this->resolveOnlyStmtAssignVar($node->stmts); - if (! $ifAssignVarExpr instanceof Expr) { - return null; - } - - $elseAssignExpr = $this->resolveOnlyStmtAssignVar($node->else->stmts); - if (! $elseAssignExpr instanceof Expr) { - return null; - } - - if (! $this->nodeComparator->areNodesEqual($ifAssignVarExpr, $elseAssignExpr)) { - return null; - } - - $ternaryIfExpr = $this->resolveOnlyStmtAssignExpr($node->stmts); - $expr = $this->resolveOnlyStmtAssignExpr($node->else->stmts); - if (! $ternaryIfExpr instanceof Expr) { - return null; - } - - if (! $expr instanceof Expr) { - return null; - } - - // has nested ternary → skip, it's super hard to read - if ($this->haveNestedTernary([$node->cond, $ternaryIfExpr, $expr])) { - return null; - } - - $ternary = new Ternary($node->cond, $ternaryIfExpr, $expr); - $assign = new Assign($ifAssignVarExpr, $ternary); - - // do not create super long lines - if ($this->isNodeTooLong($assign)) { - return null; - } - - if ($ternary->cond instanceof BinaryOp || $ternary->cond instanceof Assign) { - $ternary->cond->setAttribute(AttributeKey::ORIGINAL_NODE, null); - } - - $expression = new Expression($assign); - $this->mirrorComments($expression, $node); - - return $expression; - } - - /** - * @param Stmt[] $stmts - */ - private function resolveOnlyStmtAssignVar(array $stmts): ?Expr - { - if (count($stmts) !== 1) { - return null; - } - - $stmt = $stmts[0]; - if (! $stmt instanceof Expression) { - return null; - } - - $stmtExpr = $stmt->expr; - if (! $stmtExpr instanceof Assign) { - return null; - } - - return $stmtExpr->var; - } - - /** - * @param Stmt[] $stmts - */ - private function resolveOnlyStmtAssignExpr(array $stmts): ?Expr - { - if (count($stmts) !== 1) { - return null; - } - - $stmt = $stmts[0]; - if (! $stmt instanceof Expression) { - return null; - } - - if ($stmt->getComments() !== []) { - return null; - } - - $stmtExpr = $stmt->expr; - if (! $stmtExpr instanceof Assign) { - return null; - } - - return $stmtExpr->expr; - } - - /** - * @param Node[] $nodes - */ - private function haveNestedTernary(array $nodes): bool - { - foreach ($nodes as $node) { - $ternary = $this->betterNodeFinder->findFirstInstanceOf($node, Ternary::class); - if ($ternary instanceof Ternary) { - return true; - } - } - - return false; - } - - private function isNodeTooLong(Assign $assign): bool - { - $assignContent = $this->betterStandardPrinter->print($assign); - return strlen($assignContent) > self::LINE_LENGTH_LIMIT; + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as the result depends on context and can worsen readability; extract a method instead if needed', + self::class + )); } } diff --git a/src/Config/Level/CodeQualityLevel.php b/src/Config/Level/CodeQualityLevel.php index 2d4f4465524..b24712e76c7 100644 --- a/src/Config/Level/CodeQualityLevel.php +++ b/src/Config/Level/CodeQualityLevel.php @@ -27,6 +27,8 @@ use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector; 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\For_\ForRepeatedCountToOwnVariableRector; use Rector\CodeQuality\Rector\Foreach_\ForeachItemsAssignToEmptyArrayToAssignRector; use Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector; @@ -49,7 +51,10 @@ use Rector\CodeQuality\Rector\Identical\SimplifyArraySearchRector; use Rector\CodeQuality\Rector\Identical\SimplifyConditionsRector; use Rector\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector; +use Rector\CodeQuality\Rector\If_\ArrayExplicitBoolCompareRector; use Rector\CodeQuality\Rector\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector; +use Rector\CodeQuality\Rector\If_\ObjectExplicitBoolCompareRector; +use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; use Rector\CodeQuality\Rector\If_\SimplifyIfNotNullReturnRector; use Rector\CodeQuality\Rector\If_\SimplifyIfNullableReturnRector; use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector; @@ -137,6 +142,9 @@ final class CodeQualityLevel CompleteDynamicPropertiesRector::class, IsAWithStringWithThirdArgumentRector::class, StrlenZeroToIdenticalEmptyStringRector::class, + ArrayExplicitBoolCompareRector::class, + ObjectExplicitBoolCompareRector::class, + ShortenElseIfRector::class, ThrowWithPreviousExceptionRector::class, RemoveSoleValueSprintfRector::class, ExplicitReturnNullRector::class, @@ -154,6 +162,8 @@ final class CodeQualityLevel NewStaticToNewSelfRector::class, VariableConstFetchToClassConstFetchRector::class, SingularSwitchToIfRector::class, + InlineIfToExplicitIfRector::class, + TernaryFalseExpressionToIfRector::class, SwitchTrueToMatchRector::class, SimplifyIfNullableReturnRector::class, CallUserFuncWithArrowFunctionToInlineRector::class, diff --git a/src/Config/Level/CodingStyleLevel.php b/src/Config/Level/CodingStyleLevel.php index 4a2fe71ec84..c94c8a013f6 100644 --- a/src/Config/Level/CodingStyleLevel.php +++ b/src/Config/Level/CodingStyleLevel.php @@ -4,6 +4,7 @@ namespace Rector\Config\Level; +use Rector\CodeQuality\Rector\If_\CompleteMissingIfElseBracketRector; use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector; use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector; use Rector\CodingStyle\Rector\ClassConst\SplitGroupedClassConstantsRector; @@ -16,6 +17,7 @@ use Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector; use Rector\CodingStyle\Rector\FuncCall\StrictInArrayRector; use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector; +use Rector\CodingStyle\Rector\If_\AlternativeIfToBracketRector; use Rector\CodingStyle\Rector\Property\SplitGroupedPropertiesRector; use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; use Rector\CodingStyle\Rector\Stmt\RemoveUselessAliasInUseStatementRector; @@ -49,6 +51,8 @@ final class CodingStyleLevel SeparateMultiUseImportsRector::class, NewlineBetweenClassLikeStmtsRector::class, NewlineAfterStatementRector::class, + AlternativeIfToBracketRector::class, + CompleteMissingIfElseBracketRector::class, SimplifyQuoteEscapeRector::class, StringClassNameToClassConstantRector::class, CatchExceptionNameMatchingTypeRector::class, diff --git a/src/Set/ValueObject/SetList.php b/src/Set/ValueObject/SetList.php index 69edadc1645..b6c39b32415 100644 --- a/src/Set/ValueObject/SetList.php +++ b/src/Set/ValueObject/SetList.php @@ -136,6 +136,9 @@ final class SetList */ public const string INSTANCEOF = __DIR__ . '/../../../config/set/instanceof.php'; + /** + * @deprecated Use code-quality and coding-style sets instead, as the if rules were moved there or deprecated + */ public const string IF = __DIR__ . '/../../../config/set/if.php'; public const string CARBON = __DIR__ . '/../../../config/set/datetime-to-carbon.php'; diff --git a/tests/Issues/IfElseAssignReturnUsed/Fixture/use_on_return_after_if_else_assign.php.inc b/tests/Issues/IfElseAssignReturnUsed/Fixture/use_on_return_after_if_else_assign.php.inc deleted file mode 100644 index 626a775465c..00000000000 --- a/tests/Issues/IfElseAssignReturnUsed/Fixture/use_on_return_after_if_else_assign.php.inc +++ /dev/null @@ -1,41 +0,0 @@ -toRawArray(); - } else { - $properties = (array) $data; - } - - return $properties; - } -} - -?> ------ -toRawArray(); - } - - return (array) $data; - } -} - -?> diff --git a/tests/Issues/IfElseAssignReturnUsed/IfElseAssignReturnUsedTest.php b/tests/Issues/IfElseAssignReturnUsed/IfElseAssignReturnUsedTest.php deleted file mode 100644 index d00bd1bbc48..00000000000 --- a/tests/Issues/IfElseAssignReturnUsed/IfElseAssignReturnUsedTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/tests/Issues/IfElseAssignReturnUsed/config/configured_rule.php b/tests/Issues/IfElseAssignReturnUsed/config/configured_rule.php deleted file mode 100644 index 89b4036772d..00000000000 --- a/tests/Issues/IfElseAssignReturnUsed/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -withRules([ChangeIfElseValueAssignToEarlyReturnRector::class, SimplifyIfElseToTernaryRector::class]); diff --git a/tests/Issues/Issue7306/Fixture/fixture.php.inc b/tests/Issues/Issue7306/Fixture/fixture.php.inc deleted file mode 100644 index a6a91ea55f3..00000000000 --- a/tests/Issues/Issue7306/Fixture/fixture.php.inc +++ /dev/null @@ -1,38 +0,0 @@ - ------ - diff --git a/tests/Issues/Issue7306/RuleCombinationShouldNotSimplifyIfNotNullReturnTest.php b/tests/Issues/Issue7306/RuleCombinationShouldNotSimplifyIfNotNullReturnTest.php deleted file mode 100644 index 72aae2f279b..00000000000 --- a/tests/Issues/Issue7306/RuleCombinationShouldNotSimplifyIfNotNullReturnTest.php +++ /dev/null @@ -1,31 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/tests/Issues/Issue7306/config/configured_rule.php b/tests/Issues/Issue7306/config/configured_rule.php deleted file mode 100644 index 05a75d33ea1..00000000000 --- a/tests/Issues/Issue7306/config/configured_rule.php +++ /dev/null @@ -1,17 +0,0 @@ -withRules( - [ - SimplifyIfNotNullReturnRector::class, - ExplicitBoolCompareRector::class, - NewlineBetweenClassLikeStmtsRector::class, - ] - ); diff --git a/tests/Issues/KeepDoubleAssignParam/Fixture/fixture.php.inc b/tests/Issues/KeepDoubleAssignParam/Fixture/fixture.php.inc deleted file mode 100644 index 1e994546ab5..00000000000 --- a/tests/Issues/KeepDoubleAssignParam/Fixture/fixture.php.inc +++ /dev/null @@ -1,49 +0,0 @@ -items = [$input]; - } else { - $this->items = $input; - } - - $this->items = $this->getItems(); - } - - public function getItems() - { - return sort($this->items); - } -} - -?> ------ -items = ! \is_array($input) ? [$input] : $input; - - $this->items = $this->getItems(); - } - - public function getItems() - { - return sort($this->items); - } -} - -?> diff --git a/tests/Issues/KeepDoubleAssignParam/KeepDoubleAssignParamTest.php b/tests/Issues/KeepDoubleAssignParam/KeepDoubleAssignParamTest.php deleted file mode 100644 index 4cbe0f9c96e..00000000000 --- a/tests/Issues/KeepDoubleAssignParam/KeepDoubleAssignParamTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/tests/Issues/KeepDoubleAssignParam/config/configured_rule.php b/tests/Issues/KeepDoubleAssignParam/config/configured_rule.php deleted file mode 100644 index 0c0f164e715..00000000000 --- a/tests/Issues/KeepDoubleAssignParam/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -withRules([RemoveDoubleAssignRector::class, SimplifyIfElseToTernaryRector::class]); diff --git a/tests/Issues/SimplifyVariableIfElseTernary/Fixture/do_not_duplicated_expr.php.inc b/tests/Issues/SimplifyVariableIfElseTernary/Fixture/do_not_duplicated_expr.php.inc deleted file mode 100644 index 97b1eb8d3fa..00000000000 --- a/tests/Issues/SimplifyVariableIfElseTernary/Fixture/do_not_duplicated_expr.php.inc +++ /dev/null @@ -1,37 +0,0 @@ - 0) { - $baz = 'a'; - } else { - $baz = 'b'; - } - - return $baz; - } -} - -?> ------ - 0 ? 'a' : 'b'; - } -} - -?> diff --git a/tests/Issues/SimplifyVariableIfElseTernary/SimplifyVariableIfElseTernaryTest.php b/tests/Issues/SimplifyVariableIfElseTernary/SimplifyVariableIfElseTernaryTest.php deleted file mode 100644 index ed5c1539eab..00000000000 --- a/tests/Issues/SimplifyVariableIfElseTernary/SimplifyVariableIfElseTernaryTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/tests/Issues/SimplifyVariableIfElseTernary/config/configured_rule.php b/tests/Issues/SimplifyVariableIfElseTernary/config/configured_rule.php deleted file mode 100644 index a49cb9a6ad7..00000000000 --- a/tests/Issues/SimplifyVariableIfElseTernary/config/configured_rule.php +++ /dev/null @@ -1,17 +0,0 @@ -withRules( - [ - SimplifyIfElseToTernaryRector::class, - SimplifyUselessVariableRector::class, - CompleteDynamicPropertiesRector::class, - ] - );