Skip to content

Commit e51eabb

Browse files
authored
[PHPUnit90] Speed up AssertRegExpRector with cheap method-name gate (#796)
1 parent bc7473c commit e51eabb

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎rules/PHPUnit90/Rector/MethodCall/AssertRegExpRector.php‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ public function refactor(Node $node): ?Node
9797
continue;
9898
}
9999

100-
if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames(
101-
$stmt->expr,
100+
// cheap name gate before the costly TestCase type resolution below
101+
if (! $this->isNames(
102+
$stmt->expr->name,
102103
[self::ASSERT_SAME, self::ASSERT_EQUALS, self::ASSERT_NOT_SAME, self::ASSERT_NOT_EQUALS]
103104
)) {
104105
continue;
@@ -108,10 +109,13 @@ public function refactor(Node $node): ?Node
108109
continue;
109110
}
110111

111-
/** @var FuncCall|Node $secondArgumentValue */
112-
$secondArgumentValue = $stmt->expr->getArgs()[1]
113-
->value;
112+
$callArgs = $stmt->expr->getArgs();
113+
if (! isset($callArgs[1])) {
114+
continue;
115+
}
114116

117+
// cheap preg_match arg gate before the costly TestCase type resolution below
118+
$secondArgumentValue = $callArgs[1]->value;
115119
if (! $secondArgumentValue instanceof FuncCall) {
116120
continue;
117121
}
@@ -124,6 +128,13 @@ public function refactor(Node $node): ?Node
124128
continue;
125129
}
126130

131+
if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames(
132+
$stmt->expr,
133+
[self::ASSERT_SAME, self::ASSERT_EQUALS, self::ASSERT_NOT_SAME, self::ASSERT_NOT_EQUALS]
134+
)) {
135+
continue;
136+
}
137+
127138
$oldMethodName = $this->getName($stmt->expr->name);
128139
if ($oldMethodName === null) {
129140
continue;

0 commit comments

Comments
 (0)