Skip to content

Commit 84d7585

Browse files
committed
Fix CI failures [claude-ci-fix]
Automated fix attempt 1 for CI failures.
1 parent fb99ab3 commit 84d7585

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4207,35 +4207,59 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
42074207
continue;
42084208
}
42094209

4210-
$condNodes = [];
4211-
$conditionCases = [];
4212-
$conditionExprs = [];
4210+
// First pass: validate all conditions are enum case references
4211+
$validatedConds = [];
4212+
$allCondsValid = true;
42134213
foreach ($arm->conds as $j => $cond) {
42144214
if (!$cond instanceof Expr\ClassConstFetch) {
4215-
continue 2;
4215+
$allCondsValid = false;
4216+
break;
42164217
}
42174218
if (!$cond->class instanceof Name) {
4218-
continue 2;
4219+
$allCondsValid = false;
4220+
break;
42194221
}
42204222
if (!$cond->name instanceof Node\Identifier) {
4221-
continue 2;
4223+
$allCondsValid = false;
4224+
break;
42224225
}
42234226
$fetchedClassName = $scope->resolveName($cond->class);
42244227
$loweredFetchedClassName = strtolower($fetchedClassName);
42254228
if (!array_key_exists($loweredFetchedClassName, $indexedEnumCases)) {
4226-
continue 2;
4229+
$allCondsValid = false;
4230+
break;
42274231
}
4232+
$caseName = $cond->name->toString();
4233+
if (!array_key_exists($caseName, $indexedEnumCases[$loweredFetchedClassName])) {
4234+
$allCondsValid = false;
4235+
break;
4236+
}
4237+
$validatedConds[$j] = [
4238+
'cond' => $cond,
4239+
'loweredFetchedClassName' => $loweredFetchedClassName,
4240+
'caseName' => $caseName,
4241+
'enumCase' => $indexedEnumCases[$loweredFetchedClassName][$caseName],
4242+
];
4243+
}
4244+
4245+
if (!$allCondsValid) {
4246+
continue;
4247+
}
4248+
4249+
$condNodes = [];
4250+
$conditionCases = [];
4251+
$conditionExprs = [];
4252+
// Second pass: process validated conditions with side effects
4253+
foreach ($validatedConds as $j => $validatedCond) {
4254+
$cond = $validatedCond['cond'];
4255+
$loweredFetchedClassName = $validatedCond['loweredFetchedClassName'];
4256+
$caseName = $validatedCond['caseName'];
4257+
$enumCase = $validatedCond['enumCase'];
42284258

42294259
if (!array_key_exists($loweredFetchedClassName, $unusedIndexedEnumCases)) {
42304260
throw new ShouldNotHappenException();
42314261
}
42324262

4233-
$caseName = $cond->name->toString();
4234-
if (!array_key_exists($caseName, $indexedEnumCases[$loweredFetchedClassName])) {
4235-
continue 2;
4236-
}
4237-
4238-
$enumCase = $indexedEnumCases[$loweredFetchedClassName][$caseName];
42394263
$conditionCases[] = $enumCase;
42404264
$armConditionScope = $matchScope;
42414265
if (!array_key_exists($caseName, $unusedIndexedEnumCases[$loweredFetchedClassName])) {

tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ public function testEnums(): void
152152
'Match arm comparison between *NEVER* and MatchEnums\DifferentEnum::ONE is always false.',
153153
113,
154154
],
155+
[
156+
'Match arm comparison between MatchEnums\Foo::ONE and MatchEnums\Foo::ONE is always true.',
157+
113,
158+
'Remove remaining cases below this one and this error will disappear too.',
159+
],
155160
]);
156161
}
157162

0 commit comments

Comments
 (0)