Skip to content

Commit e45b086

Browse files
staabmondrejmirtes
authored andcommitted
CallTo*Rule: cheap checks first
1 parent b5803e6 commit e45b086

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/Rules/Methods/CallToMethodStatementWithNoDiscardRule.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public function processNode(Node $node, Scope $scope): array
5959
) {
6060
return [];
6161
}
62+
if (!$methodCall->name instanceof Node\Identifier) {
63+
return [];
64+
}
6265

6366
if ($methodCall->isFirstClassCallable()) {
6467
return [];
@@ -68,11 +71,7 @@ public function processNode(Node $node, Scope $scope): array
6871
return [];
6972
}
7073

71-
if (!$methodCall->name instanceof Node\Identifier) {
72-
return [];
73-
}
7474
$methodName = $methodCall->name->toString();
75-
7675
$typeResult = $this->ruleLevelHelper->findTypeToCheck(
7776
$scope,
7877
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $methodCall->var),

src/Rules/Methods/CallToMethodStatementWithoutSideEffectsRule.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,21 @@ public function processNode(Node $node, Scope $scope): array
3838
if ($methodCall instanceof Node\Expr\BinaryOp\Pipe) {
3939
$methodCall = $methodCall->right;
4040
}
41+
4142
if ($methodCall instanceof Node\Expr\NullsafeMethodCall) {
43+
if (!$methodCall->name instanceof Node\Identifier) {
44+
return [];
45+
}
4246
$scope = $scope->filterByTruthyValue(new Node\Expr\BinaryOp\NotIdentical($methodCall->var, new Node\Expr\ConstFetch(new Node\Name('null'))));
43-
} elseif (!$methodCall instanceof Node\Expr\MethodCall) {
47+
} elseif ($methodCall instanceof Node\Expr\MethodCall) {
48+
if (!$methodCall->name instanceof Node\Identifier) {
49+
return [];
50+
}
51+
} else {
4452
return [];
4553
}
4654

47-
if (!$methodCall->name instanceof Node\Identifier) {
48-
return [];
49-
}
5055
$methodName = $methodCall->name->toString();
51-
5256
$typeResult = $this->ruleLevelHelper->findTypeToCheck(
5357
$scope,
5458
NullsafeOperatorHelper::getNullsafeShortcircuitedExprRespectingScope($scope, $methodCall->var),

src/Rules/Methods/CallToStaticMethodStatementWithNoDiscardRule.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,15 @@ public function processNode(Node $node, Scope $scope): array
6060
if (!$methodCall instanceof Node\Expr\StaticCall) {
6161
return [];
6262
}
63-
64-
if ($methodCall->isFirstClassCallable()) {
63+
if (!$methodCall->name instanceof Node\Identifier) {
6564
return [];
6665
}
6766

68-
if (!$this->phpVersion->supportsNoDiscardAttribute()) {
67+
if ($methodCall->isFirstClassCallable()) {
6968
return [];
7069
}
7170

72-
if (!$methodCall->name instanceof Node\Identifier) {
71+
if (!$this->phpVersion->supportsNoDiscardAttribute()) {
7372
return [];
7473
}
7574

0 commit comments

Comments
 (0)