hirethunk / verbs

Verbs is an event sourcing package for PHP artisans
https://verbs.thunk.dev
MIT License
412 stars 32 forks source link

Add support for event state properties being nullable #179

Closed joshhanley closed 1 week ago

joshhanley commented 1 week ago

As an extension of PR #169 and PR #174, this PR adds support for allowing event state properties to be nullable.

At the moment, if we try to pass null into an event property that is typehinted to state like this:

class UserRequestsWithNullable extends Event
{
    public function __construct(
        public UserRequestState $user_request1,
        public ?UserRequestState $user_request2
    ) {}
}

$user_request1 = UserRequestState::new();

UserRequestsWithNullable::commit(
    user_request1: $user_request1,
    user_request2: null,
);

It throws the following error:

image

So this PR fixes it by ensuring that any state properties, that allow null and are set to null, get filtered out of the list of state properties for an event.