diff --git a/composer.json b/composer.json index 9d2bb97..f0eac8a 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "yzen.dev/plain-to-class", - "version": "1.1.2", + "version": "1.1.3", "description": "Class-transformer to transform your dataset into a structured object", "minimum-stability": "dev", "prefer-stable": true, diff --git a/composer.lock b/composer.lock index 01e99c4..8504cc1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cbe25e9b0617bcc24d6c1038aa4d8f93", + "content-hash": "dc7634fd776110304335e00357e2a312", "packages": [], "packages-dev": [ { diff --git a/src/ClassTransformer.php b/src/ClassTransformer.php index 0cf9ea8..58b4563 100644 --- a/src/ClassTransformer.php +++ b/src/ClassTransformer.php @@ -199,9 +199,9 @@ private static function dataConverting(string $className, ...$args) private static function propertyIsScalar(array|string $type): bool { if (is_array($type)) { - return count(array_intersect($type, ['int', 'float', 'string', 'bool'])) > 0; + return count(array_intersect($type, ['int', 'float', 'string', 'bool', 'mixed'])) > 0; } - return in_array($type, ['int', 'float', 'string', 'bool']); + return in_array($type, ['int', 'float', 'string', 'bool', 'mixed']); } /** diff --git a/tests/ClassTransformerFromObjectTest.php b/tests/ClassTransformerFromObjectTest.php index 81d77af..e4d7dab 100644 --- a/tests/ClassTransformerFromObjectTest.php +++ b/tests/ClassTransformerFromObjectTest.php @@ -65,6 +65,21 @@ public function testBaseObjectPhp8(): void self::assertIsFloat($userDTO->balance); } + /** + * @throws ReflectionException|ClassNotFoundException + */ + public function testMixedType(): void + { + $data = [ + 'id'=>1, + 'email'=>'test', + 'balance'=>1, + 'mixed'=> ['1'], + ]; + $userDTO = ClassTransformer::transform(UserDTO::class,$data); + self::assertInstanceOf(UserDTO::class, $userDTO); + } + /** * @throws ReflectionException|ClassNotFoundException */ diff --git a/tests/DTO/UserDTO.php b/tests/DTO/UserDTO.php index 21a41eb..a526db9 100644 --- a/tests/DTO/UserDTO.php +++ b/tests/DTO/UserDTO.php @@ -8,4 +8,5 @@ class UserDTO public int $id; public string $email; public float $balance; + public mixed $mixed; }