-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Make TimestampableEntity getter type hints nullable #2531
Conversation
Codecov ReportBase: 80.16% // Head: 80.16% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #2531 +/- ##
============================================
- Coverage 80.16% 80.16% -0.01%
Complexity 3142 3142
============================================
Files 158 158
Lines 7705 7708 +3
============================================
+ Hits 6177 6179 +2
- Misses 1528 1529 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Would love for this to receive a response, so please don't auto close. |
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.
Hi @villermen! Thank you for your first contribution.
Please, be aware about the PR's labels. It currently requires a rebase.
@@ -53,7 +53,7 @@ public function setCreatedAt(\DateTime $createdAt) | |||
/** | |||
* Returns createdAt. | |||
* | |||
* @return \DateTime | |||
* @return \DateTime|null |
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.
If we are going to allow null
as return type for these methods, I guess we should first update the hints for the properties that are being returned here.
@phansys Thanks for the review! I have rebased the PR against Side question: Is there anything against adding them as native return type? E.g., |
The reason behind that decision is to avoid issues for users that are not respecting the type hints declared in our API. Because its nature, I guess changes like this will be part of the next major release. |
Thank you @villermen! |
It is technically correct that these properties may be null when retrieved before being persisted. However in which situations would you actually call these methods before then? Is it not improper to call this method when they are nullable, wouldn't be better to throw exceptions in the situation when this data is not available yet. Making these return types nullables forces us to either throw exceptions or add assertions which are unnecessary in most cases. |
@nvdbeek I created this PR to have the documentation match the behavior, mainly to correct static type check inconsistencies I was experiencing. I would be in favor of a non-null property too, but I don't think an exception will help prevent undesirable situations. Forcing initialization of the properties upon construction (not on get) so that they are always available may also prove difficult when using traits. I wouldn't know how to approach that, but if you have an idea there a PR is probably welcome =) |
Signals nullability for return types of
TimestampableEntity::getCreatedAt()
andTimestampableEntity::getUpdatedAt()
. They may actually returnnull
when they are not yet persisted.This helps static type checkers understand this trait better.