-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: make aggregate id an interface #566
Conversation
It seems that phpunit has a problem with trait approach, we do the same in our services and it works fine 🤔 |
src/UuidAggregateIdTrait.php
Outdated
|
||
public function equals(AggregateId $other): bool | ||
{ | ||
return $this->uuid->toString() === $other->toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return $this->uuid->toString() === $other->toString(); | |
return $this->uuid->equals($other->uuid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively
return $this->uuid->toString() === $other->toString(); | |
return $other instanceof $this && $this->uuid->equals($other->uuid); |
But this comes down to semantics of if FooId
and BarId
with the same underlying UUID are equal? I would say they are not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I can easily make use of equals.
Check is done from trait, so I can't have access to field, we have to expose uuid instance on the interface to make it work?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this:
91d6c6b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the trait is mixed in to the actual class it has full private member access of other instances of the same type, so it works for me (tests pass) with this change locally:
public function equals(AggregateId $other): bool
{
return $other instanceof $this
&& $this->uuid->equals($other->uuid);
}
So we can drop exposing toUuid()
unless I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was sure that phpstan had a problem that make sense yesterday, but maybe I something else was wrong 🤔
Passes now, happy to change
Probably just the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor things, LGTM
|
No description provided.