Skip to content

Commit 7e6e901

Browse files
staabmondrejmirtes
authored andcommitted
Debug-Rules: cheap checks first
1 parent 355958d commit 7e6e901

File tree

4 files changed

+20
-32
lines changed

4 files changed

+20
-32
lines changed

src/Rules/Debug/DumpNativeTypeRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public function processNode(Node $node, Scope $scope): array
3535
return [];
3636
}
3737

38-
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
39-
if ($functionName === null) {
38+
if (count($node->getArgs()) === 0) {
4039
return [];
4140
}
4241

43-
if (strtolower($functionName) !== 'phpstan\dumpnativetype') {
42+
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
43+
if ($functionName === null) {
4444
return [];
4545
}
4646

47-
if (count($node->getArgs()) === 0) {
47+
if (strtolower($functionName) !== 'phpstan\dumpnativetype') {
4848
return [];
4949
}
5050

src/Rules/Debug/DumpPhpDocTypeRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public function processNode(Node $node, Scope $scope): array
3535
return [];
3636
}
3737

38-
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
39-
if ($functionName === null) {
38+
if (count($node->getArgs()) === 0) {
4039
return [];
4140
}
4241

43-
if (strtolower($functionName) !== 'phpstan\dumpphpdoctype') {
42+
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
43+
if ($functionName === null) {
4444
return [];
4545
}
4646

47-
if (count($node->getArgs()) === 0) {
47+
if (strtolower($functionName) !== 'phpstan\dumpphpdoctype') {
4848
return [];
4949
}
5050

src/Rules/Debug/DumpTypeRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public function processNode(Node $node, Scope $scope): array
3535
return [];
3636
}
3737

38-
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
39-
if ($functionName === null) {
38+
if (count($node->getArgs()) === 0) {
4039
return [];
4140
}
4241

43-
if (strtolower($functionName) !== 'phpstan\dumptype') {
42+
$functionName = $this->reflectionProvider->resolveFunctionName($node->name, $scope);
43+
if ($functionName === null) {
4444
return [];
4545
}
4646

47-
if (count($node->getArgs()) === 0) {
47+
if (strtolower($functionName) !== 'phpstan\dumptype') {
4848
return [];
4949
}
5050

src/Rules/Debug/FileAssertRule.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function processNode(Node $node, Scope $scope): array
4242
return [];
4343
}
4444

45+
if (count($node->getArgs()) !== 2) {
46+
return [];
47+
}
48+
4549
if (!$this->reflectionProvider->hasFunction($node->name, $scope)) {
4650
return [];
4751
}
@@ -67,15 +71,11 @@ public function processNode(Node $node, Scope $scope): array
6771
}
6872

6973
/**
70-
* @param Node\Arg[] $args
74+
* @param array{Node\Arg, Node\Arg} $args
7175
* @return list<IdentifierRuleError>
7276
*/
7377
private function processAssertType(array $args, Scope $scope): array
7478
{
75-
if (count($args) !== 2) {
76-
return [];
77-
}
78-
7979
$expectedTypeStrings = $scope->getType($args[0]->value)->getConstantStrings();
8080
if (count($expectedTypeStrings) !== 1) {
8181
return [
@@ -100,15 +100,11 @@ private function processAssertType(array $args, Scope $scope): array
100100
}
101101

102102
/**
103-
* @param Node\Arg[] $args
103+
* @param array{Node\Arg, Node\Arg} $args
104104
* @return list<IdentifierRuleError>
105105
*/
106106
private function processAssertNativeType(array $args, Scope $scope): array
107107
{
108-
if (count($args) !== 2) {
109-
return [];
110-
}
111-
112108
$expectedTypeStrings = $scope->getNativeType($args[0]->value)->getConstantStrings();
113109
if (count($expectedTypeStrings) !== 1) {
114110
return [
@@ -133,15 +129,11 @@ private function processAssertNativeType(array $args, Scope $scope): array
133129
}
134130

135131
/**
136-
* @param Node\Arg[] $args
132+
* @param array{Node\Arg, Node\Arg} $args
137133
* @return list<IdentifierRuleError>
138134
*/
139135
private function processAssertSuperType(array $args, Scope $scope): array
140136
{
141-
if (count($args) !== 2) {
142-
return [];
143-
}
144-
145137
$expectedTypeStrings = $scope->getType($args[0]->value)->getConstantStrings();
146138
if (count($expectedTypeStrings) !== 1) {
147139
return [
@@ -167,15 +159,11 @@ private function processAssertSuperType(array $args, Scope $scope): array
167159
}
168160

169161
/**
170-
* @param Node\Arg[] $args
162+
* @param array{Node\Arg, Node\Arg} $args
171163
* @return list<IdentifierRuleError>
172164
*/
173165
private function processAssertVariableCertainty(array $args, Scope $scope): array
174166
{
175-
if (count($args) !== 2) {
176-
return [];
177-
}
178-
179167
$certainty = $args[0]->value;
180168
if (!$certainty instanceof StaticCall) {
181169
return [

0 commit comments

Comments
 (0)