Description
Hello there,
We've started integrating our code a while ago with this package. In some places, we've extended over time the number of classes that are supported as input by a method.
The "worst example" (in the sense: having the greatest number of supported classes) we currently have looks like this :
public function doSomething(
LocalDate|LocalDateTime|LocalDateInterval|LocalDateTimeInterval|YearWeek|YearMonth|Year $temporal,
): void;
There's two types of input here :
brick/date-time
:LocalDate
,LocalDateTime
,YearWeek
,YearMonth
,Year
gammadia/date-time-extra
:LocalDateInterval
,LocalDateTimeInterval
Most of the time, the first thing done in such a method will be something like :
$temporal = LocalDateTimeInterval::cast($temporal);
As everyone of these objects can be represented with a LocalDateTimeInterval, which is the most "precise" of all. This allows to then use complex methods like intersects
and such, which are not necessarily implemented on each of these objects.
It would be nice if the signature of the method could simply be :
public function doSomething(Temporal $temporal): void;
(or TemporalInterval
, or some other name that would represent "any time interval").
Just having an empty* interface implemented on Brick's classes would allow that. Is that something you might be open to ?
I'm very reluctant to make a fork just for a such a simple addition, and not keen on having such complex union types either... (without taking about validation, error messages, etc... everything gets more complex)
I'll gladly submit a PR if you're OK with the idea.
Thanks for your consideration.
gnutix
*: it could also contain some methods / extend other interfaces you're definitely sure you want to have on all these objects, like Stringable
or JsonSerializable
, or even go as far as proposing methods to get time boundaries (think getStart
/ getEnd
) or compare methods (isEqualTo
, isBefore
, isAfter
...) - though it might get complex to get types right...