Skip to content

Commit 7d8174d

Browse files
committed
Resolve enumCase fetch over interface
1 parent 7490296 commit 7d8174d

13 files changed

+21
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"require": {
1515
"php": "^7.4 || ^8.0",
16-
"phpstan/phpstan": "^2.1.9"
16+
"phpstan/phpstan": "^2.1.12"
1717
},
1818
"require-dev": {
1919
"composer-runtime-api": "^2.0",

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Collector/ConstantFetchCollector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ private function getDeclaringTypesWithConstant(
207207
$possibleDescendant = $isPossibleDescendant ?? !$classReflection->isFinal();
208208

209209
if ($mayBeEnum) {
210-
$result[] = new EnumCaseRef($classReflection->getName(), $constantName);
210+
$result[] = new EnumCaseRef($classReflection->getName(), $constantName, $typeNormalized->isEnum()->maybe());
211211
}
212212

213213
$result[] = new ClassConstantRef($classReflection->getName(), $constantName, $possibleDescendant);
214214
}
215215

216216
if ($result === []) { // call over unknown type
217217
$result[] = new ClassConstantRef(null, $constantName, true);
218-
$result[] = new EnumCaseRef(null, $constantName);
218+
$result[] = new EnumCaseRef(null, $constantName, true);
219219
}
220220

221221
return $result;

src/Graph/CollectedUsage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static function deserialize(
125125
} elseif ($memberType === MemberType::ENUM_CASE) {
126126
$usage = new EnumCaseUsage(
127127
$origin,
128-
new EnumCaseRef($result['m']['c'], $result['m']['m']),
128+
new EnumCaseRef($result['m']['c'], $result['m']['m'], $result['m']['d']),
129129
);
130130
} else {
131131
throw new LogicException('Unknown member type: ' . $memberType);

src/Graph/EnumCaseRef.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
final class EnumCaseRef extends ClassMemberRef
1111
{
1212

13+
/**
14+
* @param bool $possibleDescendant Can be true only for maybe-enums (interfaces)
15+
*/
1316
public function __construct(
1417
?string $className,
15-
?string $enumCaseName
18+
?string $enumCaseName,
19+
bool $possibleDescendant
1620
)
1721
{
18-
parent::__construct($className, $enumCaseName, false);
22+
parent::__construct($className, $enumCaseName, $possibleDescendant);
1923
}
2024

2125
public static function buildKey(string $typeName, string $memberName): string

src/Graph/EnumCaseUsage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function concretizeMixedClassNameUsage(string $className): self
5151
new EnumCaseRef(
5252
$className,
5353
$this->enumCase->getMemberName(),
54+
$this->enumCase->isPossibleDescendant(),
5455
),
5556
);
5657
}

src/Provider/DoctrineUsageProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ private function getUsagesOfEnumColumn(string $className, string $propertyName,
280280
new EnumCaseRef(
281281
$constantString->getValue(),
282282
null,
283+
false,
283284
),
284285
);
285286
}

src/Provider/EnumUsageProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function getTryFromUsages(StaticCall $staticCall, Scope $scope): array
7272
continue;
7373
}
7474

75-
$valueToCaseMapping = $this->getValueToEnumCaseMapping($classReflection->getNativeReflection()); // @phpstan-ignore argument.type (https://github.com/phpstan/phpstan-src/pull/3925)
75+
$valueToCaseMapping = $this->getValueToEnumCaseMapping($classReflection->getNativeReflection());
7676
$triedValues = $firstArgType->getConstantScalarValues() === []
7777
? [null]
7878
: array_filter($firstArgType->getConstantScalarValues(), static fn($value): bool => is_string($value) || is_int($value));
@@ -81,7 +81,7 @@ private function getTryFromUsages(StaticCall $staticCall, Scope $scope): array
8181
$enumCase = $value === null ? null : $valueToCaseMapping[$value] ?? null;
8282
$result[] = new EnumCaseUsage(
8383
UsageOrigin::createRegular($staticCall, $scope),
84-
new EnumCaseRef($classReflection->getName(), $enumCase),
84+
new EnumCaseRef($classReflection->getName(), $enumCase, false),
8585
);
8686
}
8787
}

src/Provider/ReflectionBasedMemberUsageProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ private function createEnumCaseUsage(ReflectionEnumUnitCase $enumCaseReflection,
168168
new EnumCaseRef(
169169
$enumCaseReflection->getDeclaringClass()->getName(),
170170
$enumCaseReflection->getName(),
171+
false,
171172
),
172173
);
173174
}

src/Provider/ReflectionUsageProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private function createEnumCaseUsage(
251251
new EnumCaseRef(
252252
$className,
253253
$enumCaseName,
254+
false,
254255
),
255256
);
256257
}

0 commit comments

Comments
 (0)