Skip to content

Commit 1f01828

Browse files
committed
fix: nullable property
1 parent 5f78b33 commit 1f01828

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

composer.json

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

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ValueCasting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(ReflectionProperty $property, HydratorConfig $config
4747
*/
4848
public function castAttribute(mixed $value): mixed
4949
{
50-
if ($this->property->type->isNullable && empty($value)) {
50+
if ($this->property->type->isNullable && $value === null) {
5151
return null;
5252
}
5353

tests/Units/ValueCastingTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ public function testCreateProperty(): void
5050

5151

5252
$caster = new ValueCasting(new RuntimeReflectionProperty(new \ReflectionProperty(TypesDto::class, 'nullableInt')));
53-
$value = $caster->castAttribute('');
53+
$value = $caster->castAttribute(null);
5454
$this->assertNull($value);
5555

5656
$caster = new ValueCasting(new RuntimeReflectionProperty(new \ReflectionProperty(TypesDto::class, 'nullableString')));
57-
$value = $caster->castAttribute('');
57+
$value = $caster->castAttribute(null);
5858
$this->assertNull($value);
5959

6060
$caster = new ValueCasting(new RuntimeReflectionProperty(new \ReflectionProperty(TypesDto::class, 'nullableFloat')));
61-
$value = $caster->castAttribute('');
61+
$value = $caster->castAttribute(null);
6262
$this->assertNull($value);
6363

6464
$caster = new ValueCasting(new RuntimeReflectionProperty(new \ReflectionProperty(TypesDto::class, 'nullableBool')));
65-
$value = $caster->castAttribute('');
65+
$value = $caster->castAttribute(null);
6666
$this->assertNull($value);
6767
}
6868

0 commit comments

Comments
 (0)