Skip to content

Commit ed2f60b

Browse files
committed
Fixed tests
1 parent fcb78d9 commit ed2f60b

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/Analyser/TypeSpecifier.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ public function specifyTypesInCondition(
549549
$varsToIterate = [$expr->expr];
550550
}
551551
foreach ($varsToIterate as $var) {
552-
$vars[] = $var;
552+
$tmpVars = [$var];
553553

554554
while (
555555
$var instanceof ArrayDimFetch
@@ -565,16 +565,16 @@ public function specifyTypesInCondition(
565565
} else {
566566
$var = $var->var;
567567
}
568-
$vars[] = $var;
568+
$tmpVars[] = $var;
569569
}
570+
571+
$vars = array_merge($vars, array_reverse($tmpVars));
570572
}
571573

572574
if (count($vars) === 0) {
573575
throw new \PHPStan\ShouldNotHappenException();
574576
}
575577

576-
$vars = array_reverse($vars);
577-
578578
$types = null;
579579
foreach ($vars as $var) {
580580
if ($var instanceof Expr\Variable && is_string($var->name)) {

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

+18-2
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,28 @@ public function testDefinedVariables(): void
107107
'Undefined variable: $variableInEmpty',
108108
145,
109109
],
110+
[
111+
'Undefined variable: $negatedVariableInEmpty',
112+
152,
113+
],
110114
[
111115
'Undefined variable: $variableInEmpty',
112116
155,
113117
],
114118
[
115-
'Variable $negatedVariableInEmpty might not be defined.',
119+
'Undefined variable: $negatedVariableInEmpty',
116120
156,
117121
],
118122
[
119-
'Variable $variableInIsset might not be defined.',
123+
'Undefined variable: $variableInIsset',
124+
159,
125+
],
126+
[
127+
'Undefined variable: $anotherVariableInIsset',
128+
159,
129+
],
130+
[
131+
'Undefined variable: $variableInIsset',
120132
161,
121133
],
122134
[
@@ -211,6 +223,10 @@ public function testDefinedVariables(): void
211223
'Variable $forVariableUsedAndThenDefined might not be defined.',
212224
360,
213225
],
226+
[
227+
'Undefined variable: $variableInWhileIsset',
228+
365,
229+
],
214230
[
215231
'Undefined variable: $unknownVariablePassedToReset',
216232
368,

0 commit comments

Comments
 (0)