Skip to content

Commit 0871cca

Browse files
author
Яценко Андрей
committed
fixed mixed type
1 parent d7f8c02 commit 0871cca

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yzen.dev/plain-to-class",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "Class-transformer to transform your dataset into a structured object",
55
"minimum-stability": "dev",
66
"prefer-stable": true,

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ClassTransformer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ private static function dataConverting(string $className, ...$args)
199199
private static function propertyIsScalar(array|string $type): bool
200200
{
201201
if (is_array($type)) {
202-
return count(array_intersect($type, ['int', 'float', 'string', 'bool'])) > 0;
202+
return count(array_intersect($type, ['int', 'float', 'string', 'bool', 'mixed'])) > 0;
203203
}
204-
return in_array($type, ['int', 'float', 'string', 'bool']);
204+
return in_array($type, ['int', 'float', 'string', 'bool', 'mixed']);
205205
}
206206

207207
/**

tests/ClassTransformerFromObjectTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,21 @@ public function testBaseObjectPhp8(): void
6565
self::assertIsFloat($userDTO->balance);
6666
}
6767

68+
/**
69+
* @throws ReflectionException|ClassNotFoundException
70+
*/
71+
public function testMixedType(): void
72+
{
73+
$data = [
74+
'id'=>1,
75+
'email'=>'test',
76+
'balance'=>1,
77+
'mixed'=> ['1'],
78+
];
79+
$userDTO = ClassTransformer::transform(UserDTO::class,$data);
80+
self::assertInstanceOf(UserDTO::class, $userDTO);
81+
}
82+
6883
/**
6984
* @throws ReflectionException|ClassNotFoundException
7085
*/

tests/DTO/UserDTO.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class UserDTO
88
public int $id;
99
public string $email;
1010
public float $balance;
11+
public mixed $mixed;
1112
}

0 commit comments

Comments
 (0)