diff --git a/docs/en/reference/custom-mapping-types.rst b/docs/en/reference/custom-mapping-types.rst index 8e9ffad5d..cd1a11ac0 100644 --- a/docs/en/reference/custom-mapping-types.rst +++ b/docs/en/reference/custom-mapping-types.rst @@ -31,7 +31,7 @@ a ``DateTimeImmutable``. // This trait provides default closureToPHP used during data hydration use ClosureToPHP; - public function convertToPHPValue($value): ?DateTimeImmutable + public function convertToPHPValue($value): DateTimeImmutable { $timeZone = new DateTimeZone($value['tz']); $dateTime = $value['utc'] @@ -41,7 +41,7 @@ a ``DateTimeImmutable``. return DateTimeImmutable::createFromMutable($dateTime); } - public function convertToDatabaseValue($value): ?array + public function convertToDatabaseValue($value): array { return [ 'utc' => new UTCDateTime($value), diff --git a/tests/Documentation/CustomMapping/DateTimeWithTimezoneType.php b/tests/Documentation/CustomMapping/DateTimeWithTimezoneType.php index 4bad52e55..429b837d8 100644 --- a/tests/Documentation/CustomMapping/DateTimeWithTimezoneType.php +++ b/tests/Documentation/CustomMapping/DateTimeWithTimezoneType.php @@ -5,6 +5,7 @@ namespace Documentation\CustomMapping; use DateTimeImmutable; +use DateTimeInterface; use DateTimeZone; use Doctrine\ODM\MongoDB\Types\ClosureToPHP; use Doctrine\ODM\MongoDB\Types\Type; @@ -15,7 +16,8 @@ class DateTimeWithTimezoneType extends Type // This trait provides default closureToPHP used during data hydration use ClosureToPHP; - public function convertToPHPValue($value): ?DateTimeImmutable + /** @param array{utc: UTCDateTime, tz: string} $value */ + public function convertToPHPValue($value): DateTimeImmutable { $timeZone = new DateTimeZone($value['tz']); $dateTime = $value['utc'] @@ -25,7 +27,12 @@ public function convertToPHPValue($value): ?DateTimeImmutable return DateTimeImmutable::createFromMutable($dateTime); } - public function convertToDatabaseValue($value): ?array + /** + * @param DateTimeInterface $value + * + * @return array{utc: UTCDateTime, tz: string} + */ + public function convertToDatabaseValue($value): array { return [ 'utc' => new UTCDateTime($value),