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 @@ +<?php + +declare(strict_types=1); + +namespace Mapado\RestClientSdk; + +class Types +{ + public const STRING = 'string'; + public const INTEGER = 'integer'; + public const FLOAT = 'float'; + public const BOOLEAN = 'boolean'; + public const DATETIME = 'datetime'; + public const JSON_ARRAY = 'json_array'; + public const ARRAY = 'array'; +}