Skip to content

Commit 6689c09

Browse files
committed
Ignore FuncCall which takes assignment in args
1 parent 3ec2b26 commit 6689c09

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/Rules/Comparison/ImpossibleCheckTypeHelper.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,19 @@ public function findSpecifiedType(
6868
if ($node->isFirstClassCallable()) {
6969
return null;
7070
}
71-
$argsCount = count($node->getArgs());
71+
$args = $node->getArgs();
72+
$argsCount = count($args);
73+
74+
foreach ($args as $arg) {
75+
if ($arg->value instanceof Expr\Assign) {
76+
return null;
77+
}
78+
}
79+
7280
if ($node->name instanceof Node\Name) {
7381
$functionName = strtolower((string) $node->name);
7482
if ($functionName === 'assert' && $argsCount >= 1) {
75-
$arg = $node->getArgs()[0]->value;
83+
$arg = $args[0]->value;
7684
$assertValue = ($this->treatPhpDocTypesAsCertain ? $scope->getType($arg) : $scope->getNativeType($arg))->toBoolean();
7785
$assertValueIsTrue = $assertValue->isTrue()->yes();
7886
if (! $assertValueIsTrue && ! $assertValue->isFalse()->yes()) {
@@ -96,7 +104,7 @@ public function findSpecifiedType(
96104
} elseif ($functionName === 'array_search') {
97105
return null;
98106
} elseif ($functionName === 'in_array' && $argsCount >= 2) {
99-
$haystackArg = $node->getArgs()[1]->value;
107+
$haystackArg = $args[1]->value;
100108
$haystackType = ($this->treatPhpDocTypesAsCertain ? $scope->getType($haystackArg) : $scope->getNativeType($haystackArg));
101109
if ($haystackType instanceof MixedType) {
102110
return null;
@@ -106,12 +114,12 @@ public function findSpecifiedType(
106114
return null;
107115
}
108116

109-
$needleArg = $node->getArgs()[0]->value;
117+
$needleArg = $args[0]->value;
110118
$needleType = ($this->treatPhpDocTypesAsCertain ? $scope->getType($needleArg) : $scope->getNativeType($needleArg));
111119

112120
$isStrictComparison = false;
113121
if ($argsCount >= 3) {
114-
$strictNodeType = $scope->getType($node->getArgs()[2]->value);
122+
$strictNodeType = $scope->getType($args[2]->value);
115123
$isStrictComparison = $strictNodeType->isTrue()->yes();
116124
}
117125

@@ -192,7 +200,7 @@ public function findSpecifiedType(
192200
}
193201
}
194202
} elseif ($functionName === 'method_exists' && $argsCount >= 2) {
195-
$objectArg = $node->getArgs()[0]->value;
203+
$objectArg = $args[0]->value;
196204
$objectType = ($this->treatPhpDocTypesAsCertain ? $scope->getType($objectArg) : $scope->getNativeType($objectArg));
197205

198206
if ($objectType instanceof ConstantStringType
@@ -201,7 +209,7 @@ public function findSpecifiedType(
201209
return false;
202210
}
203211

204-
$methodArg = $node->getArgs()[1]->value;
212+
$methodArg = $args[1]->value;
205213
$methodType = ($this->treatPhpDocTypesAsCertain ? $scope->getType($methodArg) : $scope->getNativeType($methodArg));
206214

207215
if ($methodType instanceof ConstantStringType) {

0 commit comments

Comments
 (0)