public function getTypeOfChildProperty($targetType, $propertyName, PropertyMappingConfigurationInterface $configuration)
{
$configuredTargetType = $configuration->getConfigurationFor($propertyName)->getConfigurationValue(ObjectConverter::class, self::CONFIGURATION_TARGET_TYPE);
if ($configuredTargetType !== null) {
return $configuredTargetType;
}
$methodParameters = $this->reflectionService->getMethodParameters($targetType, '__construct');
if (isset($methodParameters[$propertyName]) && isset($methodParameters[$propertyName]['type'])) {
return $methodParameters[$propertyName]['type'];
} elseif ($this->reflectionService->hasMethod($targetType, ObjectAccess::buildSetterMethodName($propertyName))) {
$methodParameters = $this->reflectionService->getMethodParameters($targetType, ObjectAccess::buildSetterMethodName($propertyName));
$methodParameter = current($methodParameters);
if (!isset($methodParameter['type'])) {
throw new InvalidTargetException('Setter for property "' . $propertyName . '" had no type hint or documentation in target object of type "' . $targetType . '".', 1303379158);
} else {
return $methodParameter['type'];
}
} else {
$targetPropertyNames = $this->reflectionService->getClassPropertyNames($targetType);
if (in_array($propertyName, $targetPropertyNames)) {
$varTagValues = $this->reflectionService->getPropertyTagValues($targetType, $propertyName, 'var');
if (count($varTagValues) > 0) {
// This ensures that FQCNs are returned without leading backslashes. Otherwise, something like @var \DateTime
// would not find a property mapper. It is needed because the ObjectConverter doesn't use class schemata,
// but reads the annotations directly.
$declaredType = strtok(trim(current($varTagValues), " \n\t"), " \n\t");
try {
$parsedType = TypeHandling::parseType($declaredType);
} catch (InvalidTypeException $exception) {
throw new \InvalidArgumentException(sprintf($exception->getMessage(), 'class "' . $targetType . '" for property "' . $propertyName . '"'), 1467699674);
}
return $parsedType['type'] . ($parsedType['elementType'] !== null ? '<' . $parsedType['elementType'] . '>' : '');
} else {
throw new InvalidTargetException(sprintf('Public property "%s" had no proper type annotation (i.e. "@var") in target object of type "%s".', $propertyName, $targetType), 1406821818);
}
}
}
throw new InvalidTargetException(sprintf('Property "%s" has neither a setter or constructor argument, nor is public, in target object of type "%s".', $propertyName, $targetType), 1303379126);
}