Skip to content

Commit 5c3b71c

Browse files
authored
Check for method name earlier in NoUnnecessaryCollectionCallRule to avoid expensive calls to type system. (#1679)
1 parent 1c79d78 commit 5c3b71c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Rules/NoUnnecessaryCollectionCallRule.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public function processNode(Node $node, Scope $scope): array
156156
/** @var \PhpParser\Node\Identifier $name */
157157
$name = $node->name;
158158

159+
if (! in_array($name->toLowerString(), $this->shouldHandle, true)) {
160+
return [];
161+
}
162+
159163
if (! $this->isCalledOnCollection($node->var, $scope)) {
160164
// Method was not called on a collection, so no errors.
161165
return [];
@@ -175,10 +179,6 @@ public function processNode(Node $node, Scope $scope): array
175179
return [];
176180
}
177181

178-
if (! in_array($name->toLowerString(), $this->shouldHandle, true)) {
179-
return [];
180-
}
181-
182182
if ($name->toLowerString() === 'first') {
183183
if (count($node->args) === 0) {
184184
// 'first', also accepts a closure as an argument.

0 commit comments

Comments
 (0)