Skip to content

Commit

Permalink
fixed mixed type
Browse files Browse the repository at this point in the history
  • Loading branch information
Яценко Андрей committed Mar 14, 2022
1 parent d7f8c02 commit 0871cca
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/ClassTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/ClassTransformerFromObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions tests/DTO/UserDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class UserDTO
public int $id;
public string $email;
public float $balance;
public mixed $mixed;
}

0 comments on commit 0871cca

Please sign in to comment.