diff --git a/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php b/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php index 040738571..b57577848 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php +++ b/src/Bundle/ChillDocGeneratorBundle/Serializer/Normalizer/DocGenObjectNormalizer.php @@ -86,19 +86,34 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte private function getExpectedType(AttributeMetadata $attribute, ReflectionClass $reflection): string { - // we have to get the expected content - 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() - )); - } + $type = null; - 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( 'Could not determine the type for this attribute: %s. Add a return type to the method or property declaration', $attribute->getName()