From 44e9c95b9d023a88d716bb7865aa35569e2230ad Mon Sep 17 00:00:00 2001 From: Julien RAVIA Date: Mon, 10 Mar 2025 14:51:57 +0000 Subject: [PATCH] Types class constant --- src/Mapping/Attribute.php | 4 +++- src/Model/Serializer.php | 3 ++- src/Types.php | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/Types.php diff --git a/src/Mapping/Attribute.php b/src/Mapping/Attribute.php index 3ade600..eb9989b 100644 --- a/src/Mapping/Attribute.php +++ b/src/Mapping/Attribute.php @@ -4,6 +4,8 @@ namespace Mapado\RestClientSdk\Mapping; +use Mapado\RestClientSdk\Types; + /** * Class Attribute * @@ -46,7 +48,7 @@ public function __construct( $this->serializedKey = $serializedKey; $this->attributeName = $attributeName ?? $this->serializedKey; - $this->type = $type ?? 'string'; + $this->type = $type ?? Types::STRING; $this->isIdentifier = $isIdentifier; } diff --git a/src/Model/Serializer.php b/src/Model/Serializer.php index 6f98f7f..b9aec50 100644 --- a/src/Model/Serializer.php +++ b/src/Model/Serializer.php @@ -14,6 +14,7 @@ use Mapado\RestClientSdk\Mapping; use Mapado\RestClientSdk\Mapping\ClassMetadata; use Mapado\RestClientSdk\SdkClient; +use Mapado\RestClientSdk\Types; use Mapado\RestClientSdk\UnitOfWork; use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException; use Symfony\Component\PropertyAccess\PropertyAccess; @@ -154,7 +155,7 @@ public function deserialize(array $data, string $className): object } if (isset($value)) { - if ('datetime' === $attribute->getType()) { + if (Types::DATETIME === $attribute->getType()) { if (!is_string($value)) { throw new \RuntimeException( "The value for $attributeName to cast to datetime value should be a string", diff --git a/src/Types.php b/src/Types.php new file mode 100644 index 0000000..ca41386 --- /dev/null +++ b/src/Types.php @@ -0,0 +1,16 @@ +