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/sets/phpunit-code-quality.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,7 +73,6 @@
UseSpecificWillMethodRector::class,
UseSpecificWithMethodRector::class,
AssertEmptyNullableObjectToAssertInstanceofRector::class,
AssertCountWithZeroToAssertEmptyRector::class,

// avoid call on nullable object
AddInstanceofAssertForNullableInstanceRector::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.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
}
28 changes: 0 additions & 28 deletions tests/Issues/EmptyUnion/EmptyUnionTest.php

This file was deleted.

19 changes: 0 additions & 19 deletions tests/Issues/EmptyUnion/Fixture/some_test.php.inc

This file was deleted.

14 changes: 0 additions & 14 deletions tests/Issues/EmptyUnion/config/configured_rule.php

This file was deleted.

Loading