Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Fix cast with null #176

Merged
merged 2 commits into from
Apr 2, 2021
Merged

Fix cast with null #176

merged 2 commits into from
Apr 2, 2021

Conversation

bastien-phi
Copy link
Contributor

Currently, a DTO like

class ComplexDtoWithNullableProperty extends DataTransferObject
{
    public string $name;

    public ?BasicDto $other;
}

cannot be created with

new ComplexDtoWithNullableProperty(name: 'a', other: null)

because we are having a

TypeError: Only arrays and Traversables can be unpacked

vendor/spatie/data-transfer-object/src/Casters/DataTransferObjectCaster.php:17
vendor/spatie/data-transfer-object/src/Reflection/DataTransferObjectProperty.php:41

This PR fixes the issue applying the cast only when given value is not null.

@brendt brendt merged commit 35b846e into spatie:master Apr 2, 2021
@brendt
Copy link
Contributor

brendt commented Apr 2, 2021

Aah, yes, thanks for sending a PR, gonna tag immediately!

brendt added a commit that referenced this pull request Apr 2, 2021
@brendt
Copy link
Contributor

brendt commented Apr 2, 2021

@bastien-phi
Copy link
Contributor Author

Wait a minute, I'm just sending another PR

@bastien-phi
Copy link
Contributor Author

You're too quick for me ! 😂

@brendt
Copy link
Contributor

brendt commented Apr 2, 2021

I don't mind many tags ;)

@bastien-phi bastien-phi deleted the fix_cast_with_null branch April 2, 2021 07:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants