-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Uid] Add interface for getDateTime()
and apply to relevant UIDs
#47507
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
[Uid] Add interface for getDateTime()
and apply to relevant UIDs
#47507
Conversation
What about adding |
Potentially, though personally it would feel like an anti-pattern to me as the behaviour is specific to only certain implementations. |
I'm not a fan of interfaces on value objects personally. I would prefer a new method on the abstract class because it keeps things simple, and it doesn't force any extra logic on consumers. Actually, nullable return values are easier to deal with thanks to nullsafe operators. |
I like the interface, I must admit. It plays nicer with static analysis than a nullable type. We might want to find a better name though. |
|
Well, won't work since class
|
One more thing: we might want to declare |
getDateTime()
and apply to relevant UIDsgetDateTime()
and apply to relevant UIDs
@nicolas-grekas is psalm failing on the intersection for |
Looks like so 🤷 |
Thank you @shrikeh. |
…elevant UIDs (shrikeh) This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [Uid] Add interface for `getDateTime()` and apply to relevant UIDs | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | Unclear how this would be documented. Minor "feature" of better describing that certain flavours of UID have embedded DateTimeImmutable. The method `getDateTime()` is described in the interface, and applied to the relevant UID flavours. This allows usage of the functionality through simpler `instanceof` inspection, or as a typed property of a class representing an entity. A trivial example: ```php if ($uid instanceof DateTimeUidInterface) { return $uid->getDateTime(); } // throw an Exception if not, or return a default DateTimeImmutable... ``` Commits ------- 0f1bc36 [Uid] Add interface for `getDateTime()` and apply to relevant UIDs
Minor "feature" of better describing that certain flavours of UID have embedded DateTimeImmutable. The method
getDateTime()
is described in the interface, and applied to the relevant UID flavours. This allows usage of the functionality through simplerinstanceof
inspection, or as a typed property of a class representing an entity. A trivial example: