Skip to content

Commit fda9e6b

Browse files
committed
Resolve enumCase fetch over interface
1 parent 21eb267 commit fda9e6b

13 files changed

+26
-18
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: 6 additions & 6 deletions
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
@@ -198,15 +198,15 @@ private function getDeclaringTypesWithConstant(
198198
$possibleDescendant = $isPossibleDescendant ?? !$classReflection->isFinal();
199199

200200
if ($mayBeEnum) {
201-
$result[] = new EnumCaseRef($classReflection->getName(), $constantName);
201+
$result[] = new EnumCaseRef($classReflection->getName(), $constantName, $typeNormalized->isEnum()->maybe());
202202
}
203203

204204
$result[] = new ClassConstantRef($classReflection->getName(), $constantName, $possibleDescendant);
205205
}
206206

207207
if ($result === []) { // call over unknown type
208208
$result[] = new ClassConstantRef(null, $constantName, true);
209-
$result[] = new EnumCaseRef(null, $constantName);
209+
$result[] = new EnumCaseRef(null, $constantName, true);
210210
}
211211

212212
return $result;

src/Graph/CollectedUsage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static function deserialize(string $data, string $scopeFile): self
122122
} elseif ($memberType === MemberType::ENUM_CASE) {
123123
$usage = new EnumCaseUsage(
124124
$origin,
125-
new EnumCaseRef($result['m']['c'], $result['m']['m']),
125+
new EnumCaseRef($result['m']['c'], $result['m']['m'], $result['m']['d']),
126126
);
127127
} else {
128128
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
@@ -262,6 +262,7 @@ private function getUsagesOfEnumColumn(string $className, string $propertyName,
262262
new EnumCaseRef(
263263
$constantString->getValue(),
264264
null,
265+
false,
265266
),
266267
);
267268
}

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
@@ -159,6 +159,7 @@ private function createEnumCaseUsage(ReflectionEnumUnitCase $enumCaseReflection,
159159
new EnumCaseRef(
160160
$enumCaseReflection->getDeclaringClass()->getName(),
161161
$enumCaseReflection->getName(),
162+
false,
162163
),
163164
);
164165
}

src/Provider/ReflectionUsageProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ private function createEnumCaseUsage(
242242
new EnumCaseRef(
243243
$className,
244244
$enumCaseName,
245+
false,
245246
),
246247
);
247248
}

0 commit comments

Comments
 (0)