-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Type hint for \DateTimeInterface instead of \DateTime #7174
Type hint for \DateTimeInterface instead of \DateTime #7174
Conversation
c5693e4
to
f177dec
Compare
Thank you for your contribution! Did you try to actually exchange |
@schmengler - there are no methods on Though there might be subtle changes/bugs in M2's behaviour, that would just point out the fact that mutable states create problems. |
Nice! :) Was thinking of such change and wasn't aware there is even PR proposed already. The only thing missing as to me is static test enforcement, so that |
@@ -162,7 +162,7 @@ public function date($date = null, $locale = null, $useTimezone = true) | |||
|
|||
if (empty($date)) { | |||
return new \DateTime('now', new \DateTimeZone($timezone)); | |||
} elseif ($date instanceof \DateTime) { | |||
} elseif ($date instanceof \DateTimeInterface) { | |||
return $date->setTimezone(new \DateTimeZone($timezone)); |
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.
setTimezone
is not part of DateTimeInterface
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 think the only thing we can do here for best DX is to internally convert the DateTimeImmutable
to DateTime
and enforce the return type hint of DateTime
always
Yes, but there are two problems:
Type hinting against But you cannot replace
but then check explicitly for Can you please review your changes again? I found at least one occurence of |
I'll take another look at this and revert the typehints where it would break code |
Haven't forgotten about this :) |
Please also add a |
f177dec
to
d53cbba
Compare
68267c2
to
cb12ace
Compare
This has been updated now. @schmengler - the test failures are unrelated. |
…nto use-date-time-interface-in-instanceof-checks
@jameshalsall I believe test failures are related, since the tests in question are green on the |
Actually, test failures identical to the build are reproducible if you run the whole suite of unit tests, for instance |
…nto use-date-time-interface-in-instanceof-checks
Thanks for chiming in @ishakhsuvarov |
- Updated unit test which changed default timezone and affected all test suite - Updated copyright to the up-to-date version
@jameshalsall @schmengler Since DataProvider seems to be executed before setUp I had to slightly shuffle the order of things in the unit test. Currently it does not look as good and logical as it should be, however I've pushed it to make sure builds are passing. We can improve it afterwards. |
- Updated copyright to the up-to-date version
@ishakhsuvarov thanks for fixing, I'm pretty sure I had addressed that previously but I may have removed it by accident |
…nto use-date-time-interface-in-instanceof-checks
This change allows userland code to pass instances of \DateTimeImmutable as well as \DateTime by using \DateTimeInterface in type hints instead of the more strict \DateTime.