-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Update Entities to use Doctrine 2.6 types #659
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
Conversation
What can we do here to move forward?
Thanks! |
When you pass the same datetime object to two components and one of them adds a day without cloning, the immutable type won't affect the other component, but the mutable will change in both places. It is quite hard to find such bugs. |
@jkufner yes, that's the theory part. But now, focusing exclusively on practice, which bug does this change fix or what real improvement does it bring to this specific application? Thanks! |
@javiereguiluz When there is no bug, it does not matter which of the types you use, but you can never be sure there is no bug. Immutable types make code more robust and bugs easier to locate. This change will pay off when some one will modify or build on the application and makes a mistake in the process. |
@jkufner yes, in general that's true. But in this specific application, which is the benefit of this change? I'm not saying there's none, I just don't see it and that's why I'm asking. |
@javiereguiluz It is a good practice and a precaution for the future. Something that an example app should highlight. The code itself does the same. |
I assume we cannot move forward here until the underlying libs have fixed the immutable usage. If @javiereguiluz sees no benefit for now this PR and #620 may be closed. |
Let's ask other regular contributors of this repository to see if they agree with this change or prefer to close it (and add it back later when things improve): @yceruto @voronkovich @bocharsky-bw. Thanks! |
Sadly the Form Component is not ready completely to return a So we might have to do something to fix it, probably into |
{ | ||
return $this->publishedAt; | ||
} | ||
|
||
public function setPublishedAt(\DateTime $publishedAt): void | ||
public function setPublishedAt(\DateTimeInterface $publishedAt): void |
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.
Should be \DateTimeImmutable
to avoid \DateTime
instances, same for Comment::setPublishedAt()
.
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.
Otherwise, we can convert here to immutable date time if needed:
if ($publishedAt instanceof \DateTime) {
$publishedAt = \DateTimeImmutable::createFromMutable($publishedAt);
}
$this->publishedAt = $publishedAt;
Same for Comment::setPublishedAt()
.
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.
@yceruto, What about to create a data transformer for those properties?
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.
Yes, it could be so, but still I'm not sure if it's worth it right now.
I agree with @jkufner that the usage of the |
@@ -162,12 +162,12 @@ public function setContent(string $content): void | |||
$this->content = $content; | |||
} | |||
|
|||
public function getPublishedAt(): \DateTime | |||
public function getPublishedAt(): \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.
Should be \DateTimeImmutable
.
If the Form component doesn't support immutable dates, that's a huge blocker for me. Is there any open pull request to improve the Form component about this? Will it be merged soon? If not, I'm afraid we should close this as "can't fix" until the Form component improves. |
As already mentioned in #620 - I guess that somebody has to pick up this unfinished PR symfony/symfony#19889 before it makes sense to continue here. |
@javiereguiluz, @gabel we could use a |
Let's close this until Symfony Forms fully support immutable dates (which sadly could take a lot of time!) Meanwhile, I've extracted in #669 the part of this pull request unrelated to immutable dates. Thank you all for the discussion. |
Tests will fail due to DateTime conversion of
handleRequest()
(src/Controller/Admin/BlogController.php:84)