Skip to content

Commit 7e35a93

Browse files
committed
resolve class constant types when patching return types
1 parent d83167d commit 7e35a93

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Symfony/Component/ErrorHandler/DebugClassLoader.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,26 @@ private function setReturnType(string $types, string $class, string $method, str
849849
$docTypes = [];
850850

851851
foreach ($typesMap as $n => $t) {
852+
if (str_contains($n, '::')) {
853+
[$definingClass, $constantName] = explode('::', $n, 2);
854+
$definingClass = match ($definingClass) {
855+
'self', 'static', 'parent' => $class,
856+
default => $definingClass,
857+
};
858+
859+
if (!\defined($definingClass.'::'.$definingClass)) {
860+
return;
861+
}
862+
863+
$constant = new \ReflectionClassConstant($definingClass, $constantName);
864+
865+
if (method_exists(\ReflectionClassConstant::class, 'getType') && $constantType = $constant->getType()) {
866+
$n = $constantType->getName();
867+
} else {
868+
$n = gettype($constant->getValue());
869+
}
870+
}
871+
852872
if ('null' === $n) {
853873
$nullable = true;
854874
continue;
@@ -872,10 +892,11 @@ private function setReturnType(string $types, string $class, string $method, str
872892
continue;
873893
}
874894

875-
if (!isset($phpTypes[''])) {
895+
if (!isset($phpTypes['']) && !\in_array($n, $phpTypes, true)) {
876896
$phpTypes[] = $n;
877897
}
878898
}
899+
879900
$docTypes = array_merge([], ...$docTypes);
880901

881902
if (!$phpTypes) {

0 commit comments

Comments
 (0)