Skip to content

Commit 797c219

Browse files
authored
Merge pull request #133 from mapado/jr-feat-types
Types class constant
2 parents 4eda6d1 + 44e9c95 commit 797c219

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/Mapping/Attribute.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Mapado\RestClientSdk\Mapping;
66

7+
use Mapado\RestClientSdk\Types;
8+
79
/**
810
* Class Attribute
911
*
@@ -46,7 +48,7 @@ public function __construct(
4648

4749
$this->serializedKey = $serializedKey;
4850
$this->attributeName = $attributeName ?? $this->serializedKey;
49-
$this->type = $type ?? 'string';
51+
$this->type = $type ?? Types::STRING;
5052
$this->isIdentifier = $isIdentifier;
5153
}
5254

src/Model/Serializer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Mapado\RestClientSdk\Mapping;
1515
use Mapado\RestClientSdk\Mapping\ClassMetadata;
1616
use Mapado\RestClientSdk\SdkClient;
17+
use Mapado\RestClientSdk\Types;
1718
use Mapado\RestClientSdk\UnitOfWork;
1819
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
1920
use Symfony\Component\PropertyAccess\PropertyAccess;
@@ -154,7 +155,7 @@ public function deserialize(array $data, string $className): object
154155
}
155156

156157
if (isset($value)) {
157-
if ('datetime' === $attribute->getType()) {
158+
if (Types::DATETIME === $attribute->getType()) {
158159
if (!is_string($value)) {
159160
throw new \RuntimeException(
160161
"The value for $attributeName to cast to datetime value should be a string",

src/Types.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Mapado\RestClientSdk;
6+
7+
class Types
8+
{
9+
public const STRING = 'string';
10+
public const INTEGER = 'integer';
11+
public const FLOAT = 'float';
12+
public const BOOLEAN = 'boolean';
13+
public const DATETIME = 'datetime';
14+
public const JSON_ARRAY = 'json_array';
15+
public const ARRAY = 'array';
16+
}

0 commit comments

Comments
 (0)