Skip to content

Commit 28065e5

Browse files
committed
[deprecated] Deprecate AssertCountWithZeroToAssertEmptyRector to improve test readability with more explicit methods
1 parent 0d8fbf8 commit 28065e5

File tree

13 files changed

+4
-254
lines changed

13 files changed

+4
-254
lines changed

config/sets/phpunit-code-quality.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Rector\PHPUnit\CodeQuality\Rector\Foreach_\SimplifyForeachInstanceOfRector;
1717
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCompareOnCountableWithMethodToAssertCountRector;
1818
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertComparisonToSpecificMethodRector;
19-
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector;
2019
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
2120
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector;
2221
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEqualsToSameRector;
@@ -74,7 +73,6 @@
7473
UseSpecificWillMethodRector::class,
7574
UseSpecificWithMethodRector::class,
7675
AssertEmptyNullableObjectToAssertInstanceofRector::class,
77-
AssertCountWithZeroToAssertEmptyRector::class,
7876

7977
// avoid call on nullable object
8078
AddInstanceofAssertForNullableInstanceRector::class,

rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/AssertCountWithZeroToAssertEmptyRectorTest.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/count_to_empty.php.inc

Lines changed: 0 additions & 39 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_first_class_callable.php.inc

Lines changed: 0 additions & 16 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_non_test_class.php.inc

Lines changed: 0 additions & 16 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_on_non_zero_argument.php.inc

Lines changed: 0 additions & 16 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Fixture/skip_union_type.php.inc

Lines changed: 0 additions & 14 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/Source/Collection.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

rules-tests/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector/config/configured_rule.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

rules/CodeQuality/Rector/MethodCall/AssertCountWithZeroToAssertEmptyRector.php

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Expr\MethodCall;
99
use PhpParser\Node\Expr\StaticCall;
10-
use PhpParser\Node\Name;
11-
use PHPStan\Type\UnionType;
10+
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
1211
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1312
use Rector\Rector\AbstractRector;
1413
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1514
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
1615

1716
/**
18-
* @see \Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector\AssertCountWithZeroToAssertEmptyRectorTest
17+
* @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.
1918
*/
20-
final class AssertCountWithZeroToAssertEmptyRector extends AbstractRector
19+
final class AssertCountWithZeroToAssertEmptyRector extends AbstractRector implements DeprecatedInterface
2120
{
2221
public function __construct(
2322
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
@@ -57,43 +56,7 @@ public function getNodeTypes(): array
5756
*/
5857
public function refactor(Node $node): MethodCall|StaticCall|null
5958
{
60-
if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertCount', 'assertNotCount'])) {
61-
return null;
62-
}
63-
64-
if ($node->isFirstClassCallable()) {
65-
return null;
66-
}
67-
68-
if (count($node->getArgs()) < 2) {
69-
return null;
70-
}
71-
72-
$type = $this->getType($node->getArgs()[0]->value);
73-
74-
if ($type instanceof UnionType) {
75-
return null;
76-
}
77-
78-
$secondType = $this->getType($node->getArgs()[1]->value);
79-
if ($secondType instanceof UnionType) {
80-
return null;
81-
}
82-
83-
$value = ($type->getConstantScalarValues()[0] ?? null);
84-
if ($value === 0) {
85-
$args = $node->getArgs();
86-
if ($this->isName($node->name, 'assertNotCount')) {
87-
$node->name = new Name('assertNotEmpty');
88-
} else {
89-
$node->name = new Name('assertEmpty');
90-
}
91-
92-
array_shift($args);
93-
$node->args = $args;
94-
return $node;
95-
}
96-
59+
// deprecated
9760
return null;
9861
}
9962
}

0 commit comments

Comments
 (0)