private function transformLinkStatus(PropertyMetadata $propertyMetadata, array $normalizationGroups = null, array $denormalizationGroups = null) : PropertyMetadata
{
$propertyMetadata = $propertyMetadata->withReadableLink(true);
$propertyMetadata = $propertyMetadata->withWritableLink(true);
// No need to check link status if property is not readable and not writable
if (false === $propertyMetadata->isReadable() && false === $propertyMetadata->isWritable()) {
return $propertyMetadata;
}
$type = $propertyMetadata->getType();
if (null === $type) {
return $propertyMetadata;
}
$relatedClass = $type->isCollection() && ($collectionValueType = $type->getCollectionValueType()) ? $collectionValueType->getClassName() : $type->getClassName();
if (null === $relatedClass) {
return $propertyMetadata;
}
// No need to check link status if related class is not a resource
try {
$this->resourceMetadataFactory->create($relatedClass);
} catch (ResourceClassNotFoundException $e) {
return $propertyMetadata;
}
$relatedGroups = $this->getResourceSerializerGroups($relatedClass);
$propertyMetadata = $propertyMetadata->withReadableLink(null !== $normalizationGroups && !empty(array_intersect($normalizationGroups, $relatedGroups)));
$propertyMetadata = $propertyMetadata->withWritableLink(null !== $denormalizationGroups && !empty(array_intersect($denormalizationGroups, $relatedGroups)));
return $propertyMetadata;
}