diff --git a/config/sets/phpunit-code-quality.php b/config/sets/phpunit-code-quality.php index b1c9f15b..7331c97c 100644 --- a/config/sets/phpunit-code-quality.php +++ b/config/sets/phpunit-code-quality.php @@ -16,7 +16,6 @@ use Rector\PHPUnit\CodeQuality\Rector\Foreach_\SimplifyForeachInstanceOfRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCompareOnCountableWithMethodToAssertCountRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertComparisonToSpecificMethodRector; -use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector; @@ -74,7 +73,6 @@ UseSpecificWillMethodRector::class, UseSpecificWithMethodRector::class, AssertEmptyNullableObjectToAssertInstanceofRector::class, - AssertCountWithZeroToAssertEmptyRector::class, // avoid call on nullable object AddInstanceofAssertForNullableInstanceRector::class, diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/AssertCountWithZeroToAssertEmptyRectorTest.php b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/AssertCountWithZeroToAssertEmptyRectorTest.php deleted file mode 100644 index 9d7bb53c..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/AssertCountWithZeroToAssertEmptyRectorTest.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/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/count_to_empty.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/count_to_empty.php.inc deleted file mode 100644 index 1885955f..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/count_to_empty.php.inc +++ /dev/null @@ -1,39 +0,0 @@ -assertCount(0, $collection); - $this->assertCount(0, $collection, 'message here!'); - $this->assertNotCount(0, $collection); - $this->assertNotCount(0, $collection, 'message here!'); - } -} - -?> ------ -assertEmpty($collection); - $this->assertEmpty($collection, 'message here!'); - $this->assertNotEmpty($collection); - $this->assertNotEmpty($collection, 'message here!'); - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_first_class_callable.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_first_class_callable.php.inc deleted file mode 100644 index ffc45b0e..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_first_class_callable.php.inc +++ /dev/null @@ -1,16 +0,0 @@ -assertCount(...); - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_non_test_class.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_non_test_class.php.inc deleted file mode 100644 index 4181e428..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_non_test_class.php.inc +++ /dev/null @@ -1,16 +0,0 @@ -assertCount(0, $collection); - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_non_zero_argument.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_non_zero_argument.php.inc deleted file mode 100644 index bb9e643e..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_non_zero_argument.php.inc +++ /dev/null @@ -1,16 +0,0 @@ -assertCount(5, $collection); - } -} - -?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_union_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_union_type.php.inc deleted file mode 100644 index f174f98c..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_union_type.php.inc +++ /dev/null @@ -1,14 +0,0 @@ -assertCount($count, $something); - } - } -} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Source/Collection.php b/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Source/Collection.php deleted file mode 100644 index 498aef34..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Source/Collection.php +++ /dev/null @@ -1,11 +0,0 @@ -rule(AssertCountWithZeroToAssertEmptyRector::class); -}; diff --git a/rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php b/rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php index d45491b4..cc4c353f 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php @@ -7,23 +7,16 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\Name; -use PHPStan\Type\UnionType; -use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector\AssertCountWithZeroToAssertEmptyRectorTest + * @deprecated This rule is deprecated and will be removed in future releases. The use of empty() is discouraged as it introduces ambiguity. PHPStan and Rector promote refactoring away from empty() to more explicit readable structures. */ -final class AssertCountWithZeroToAssertEmptyRector extends AbstractRector +final class AssertCountWithZeroToAssertEmptyRector extends AbstractRector implements DeprecatedInterface { - public function __construct( - private readonly TestsNodeAnalyzer $testsNodeAnalyzer - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -57,43 +50,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): MethodCall|StaticCall|null { - if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertCount', 'assertNotCount'])) { - return null; - } - - if ($node->isFirstClassCallable()) { - return null; - } - - if (count($node->getArgs()) < 2) { - return null; - } - - $type = $this->getType($node->getArgs()[0]->value); - - if ($type instanceof UnionType) { - return null; - } - - $secondType = $this->getType($node->getArgs()[1]->value); - if ($secondType instanceof UnionType) { - return null; - } - - $value = ($type->getConstantScalarValues()[0] ?? null); - if ($value === 0) { - $args = $node->getArgs(); - if ($this->isName($node->name, 'assertNotCount')) { - $node->name = new Name('assertNotEmpty'); - } else { - $node->name = new Name('assertEmpty'); - } - - array_shift($args); - $node->args = $args; - return $node; - } - + // deprecated return null; } } diff --git a/tests/Issues/EmptyUnion/EmptyUnionTest.php b/tests/Issues/EmptyUnion/EmptyUnionTest.php deleted file mode 100644 index 172f2461..00000000 --- a/tests/Issues/EmptyUnion/EmptyUnionTest.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/EmptyUnion/Fixture/some_test.php.inc b/tests/Issues/EmptyUnion/Fixture/some_test.php.inc deleted file mode 100644 index 0ed8cb7c..00000000 --- a/tests/Issues/EmptyUnion/Fixture/some_test.php.inc +++ /dev/null @@ -1,19 +0,0 @@ -assertCount(0, $this->someCall()); - } - - public function someCall(): ?ArrayIterator - { - return new ArrayIterator([]); - } -} diff --git a/tests/Issues/EmptyUnion/config/configured_rule.php b/tests/Issues/EmptyUnion/config/configured_rule.php deleted file mode 100644 index 50002ef0..00000000 --- a/tests/Issues/EmptyUnion/config/configured_rule.php +++ /dev/null @@ -1,14 +0,0 @@ -rules([ - AssertCountWithZeroToAssertEmptyRector::class, - AssertEmptyNullableObjectToAssertInstanceofRector::class, - ]); -};