Skip to content

Commit

Permalink
Rule improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfox committed Aug 15, 2024
1 parent 9a1c13f commit 8746d9d
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\PHPUnit\CodeQuality\Rector\MethodCall;

use Countable;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\MethodCall;
Expand All @@ -28,17 +27,20 @@ public function __construct(

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('', [
new CodeSample(
<<<'CODE_SAMPLE'
$this->assertSame(1, $countable->count());
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
$this->assertCount(1, $countable);
CODE_SAMPLE
),
]);
return new RuleDefinition(
'Replaces use of assertSame and assertEquals on Countable objects with count method',
[
new CodeSample(
<<<'CODE_SAMPLE'
$this->assertSame(1, $countable->count());
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
$this->assertCount(1, $countable);
CODE_SAMPLE
),
]
);
}

/**
Expand Down Expand Up @@ -73,7 +75,7 @@ public function refactor(Node $node): MethodCall|StaticCall|null
) {
$type = $this->getType($right->var);

if ((new ObjectType(Countable::class))->isSuperTypeOf($type)->yes()) {
if ((new ObjectType('Countable'))->isSuperTypeOf($type)->yes()) {
$args = $node->getArgs();
$args[1] = new Arg($right->var);

Expand Down

0 comments on commit 8746d9d

Please sign in to comment.