Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types class constant #133

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Mapping/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Mapado\RestClientSdk\Mapping;

use Mapado\RestClientSdk\Types;

/**
* Class Attribute
*
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Model/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions src/Types.php
Original file line number Diff line number Diff line change
@@ -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';
}