diff --git a/CHANGELOG.md b/CHANGELOG.md index 85bb767..e94507d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.5.13 * docs: Add rationale. +* fix: Add variance safeguard. ## 0.5.12 diff --git a/src/Mapping/MappingEntry.php b/src/Mapping/MappingEntry.php index 6bcd1fe..d571de5 100644 --- a/src/Mapping/MappingEntry.php +++ b/src/Mapping/MappingEntry.php @@ -66,6 +66,14 @@ public function getClass(): string public function isVariantTargetType(): bool { + if ($this->targetType instanceof MixedType) { + return true; + } + + if ($this->targetType->getBuiltinType() !== Type::BUILTIN_TYPE_OBJECT) { + return false; + } + return $this->variantTargetType; } diff --git a/src/TransformerRegistry/SearchResultEntry.php b/src/TransformerRegistry/SearchResultEntry.php index fd8c10e..cdfe6a7 100644 --- a/src/TransformerRegistry/SearchResultEntry.php +++ b/src/TransformerRegistry/SearchResultEntry.php @@ -44,6 +44,14 @@ public function getMappingOrder(): int public function isVariantTargetType(): bool { + if ($this->targetType instanceof MixedType) { + return true; + } + + if ($this->targetType->getBuiltinType() !== Type::BUILTIN_TYPE_OBJECT) { + return false; + } + return $this->variantTargetType; }