Skip to content

Commit b12db14

Browse files
phpstan-botclaude
andcommitted
Deduplicate RuleErrorBuilder call in EnumCaseOutsideEnumRule
Restructure the condition logic to return early for the valid case (enum context) and have a single RuleErrorBuilder call for all invalid contexts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f97c99a commit b12db14

1 file changed

Lines changed: 1 addition & 15 deletions

File tree

src/Rules/EnumCases/EnumCaseOutsideEnumRule.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,7 @@ public function getNodeType(): string
2222

2323
public function processNode(Node $node, Scope $scope): array
2424
{
25-
if ($scope->isInTrait()) {
26-
return [
27-
RuleErrorBuilder::message('Enum case can only be used in enums.')
28-
->nonIgnorable()
29-
->identifier('enum.caseOutsideOfEnum')
30-
->build(),
31-
];
32-
}
33-
34-
if (!$scope->isInClass()) {
35-
return [];
36-
}
37-
38-
$classReflection = $scope->getClassReflection();
39-
if ($classReflection->isEnum()) {
25+
if (!$scope->isInTrait() && $scope->isInClass() && $scope->getClassReflection()->isEnum()) {
4026
return [];
4127
}
4228

0 commit comments

Comments
 (0)