mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
handle finding returnType on property type on parent classes
This commit is contained in:
parent
de4e83b3fb
commit
9f43c99acc
@ -86,19 +86,34 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
|||||||
|
|
||||||
private function getExpectedType(AttributeMetadata $attribute, ReflectionClass $reflection): string
|
private function getExpectedType(AttributeMetadata $attribute, ReflectionClass $reflection): string
|
||||||
{
|
{
|
||||||
// we have to get the expected content
|
$type = null;
|
||||||
if ($reflection->hasProperty($attribute->getName())) {
|
|
||||||
$type = $reflection->getProperty($attribute->getName())->getType();
|
|
||||||
} elseif ($reflection->hasMethod($attribute->getName())) {
|
|
||||||
$type = $reflection->getMethod($attribute->getName())->getReturnType();
|
|
||||||
} else {
|
|
||||||
throw new \LogicException(sprintf(
|
|
||||||
'Could not determine how the content is determined for the attribute %s. Add attribute property only on property or method',
|
|
||||||
$attribute->getName()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $type) {
|
do {
|
||||||
|
// we have to get the expected content
|
||||||
|
if ($reflection->hasProperty($attribute->getName())) {
|
||||||
|
if (!$reflection->getProperty($attribute->getName())->hasType()) {
|
||||||
|
throw new \LogicException(sprintf(
|
||||||
|
'Could not determine how the content is determined for the attribute %s. Add a type on this property',
|
||||||
|
$attribute->getName()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = $reflection->getProperty($attribute->getName())->getType();
|
||||||
|
} elseif ($reflection->hasMethod($attribute->getName())) {
|
||||||
|
if (!$reflection->getMethod($attribute->getName())->hasReturnType()) {
|
||||||
|
throw new \LogicException(sprintf(
|
||||||
|
'Could not determine how the content is determined for the attribute %s. Add a return type on the method',
|
||||||
|
$attribute->getName()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$type = $reflection->getMethod($attribute->getName())->getReturnType();
|
||||||
|
} else {
|
||||||
|
$reflection = $reflection->getParentClass();
|
||||||
|
}
|
||||||
|
} while (null === $type && $reflection instanceof ReflectionClass);
|
||||||
|
|
||||||
|
if (null === $type ?? null) {
|
||||||
throw new \LogicException(sprintf(
|
throw new \LogicException(sprintf(
|
||||||
'Could not determine the type for this attribute: %s. Add a return type to the method or property declaration',
|
'Could not determine the type for this attribute: %s. Add a return type to the method or property declaration',
|
||||||
$attribute->getName()
|
$attribute->getName()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user