diff --git a/rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php b/rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php index ead35169..9c740f0d 100644 --- a/rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php +++ b/rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php @@ -97,8 +97,9 @@ public function refactor(Node $node): ?Node continue; } - if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames( - $stmt->expr, + // cheap name gate before the costly TestCase type resolution below + if (! $this->isNames( + $stmt->expr->name, [self::ASSERT_SAME, self::ASSERT_EQUALS, self::ASSERT_NOT_SAME, self::ASSERT_NOT_EQUALS] )) { continue; @@ -108,10 +109,13 @@ public function refactor(Node $node): ?Node continue; } - /** @var FuncCall|Node $secondArgumentValue */ - $secondArgumentValue = $stmt->expr->getArgs()[1] - ->value; + $callArgs = $stmt->expr->getArgs(); + if (! isset($callArgs[1])) { + continue; + } + // cheap preg_match arg gate before the costly TestCase type resolution below + $secondArgumentValue = $callArgs[1]->value; if (! $secondArgumentValue instanceof FuncCall) { continue; } @@ -124,6 +128,13 @@ public function refactor(Node $node): ?Node continue; } + if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames( + $stmt->expr, + [self::ASSERT_SAME, self::ASSERT_EQUALS, self::ASSERT_NOT_SAME, self::ASSERT_NOT_EQUALS] + )) { + continue; + } + $oldMethodName = $this->getName($stmt->expr->name); if ($oldMethodName === null) { continue;