Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
final class ReplaceAtMethodWithDesiredMatcherRector extends AbstractRector
{
private bool $hasChanged = false;

public function __construct(
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
) {
Expand Down Expand Up @@ -59,6 +61,8 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): null|MethodCall
{
$this->hasChanged = false;

if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
Expand All @@ -67,6 +71,10 @@ public function refactor(Node $node): null|MethodCall
$this->replaceWithDesiredMatcher($arg);
}

if ($this->hasChanged) {
return $node;
}

return null;
}

Expand Down Expand Up @@ -106,10 +114,13 @@ private function replaceWithDesiredMatcher(Arg $arg): void

if ($count === 0) {
$arg->value = new MethodCall($arg->value->var, 'never');
$this->hasChanged = true;
} elseif ($count === 1) {
$arg->value = new MethodCall($arg->value->var, 'once');
$this->hasChanged = true;
} elseif ($count > 1) {
$arg->value = new MethodCall($arg->value->var, 'exactly', [new Arg(new Int_($count))]);
$this->hasChanged = true;
}
}
}
Loading