-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,9 +83,9 @@ class Post | |
private $content; | ||
|
||
/** | ||
* @var \DateTime | ||
* @var \DateTimeImmutable | ||
* | ||
* @ORM\Column(type="datetime") | ||
* @ORM\Column(type="datetime_immutable") | ||
* @Assert\DateTime | ||
*/ | ||
private $publishedAt; | ||
|
@@ -122,7 +122,7 @@ class Post | |
|
||
public function __construct() | ||
{ | ||
$this->publishedAt = new \DateTime(); | ||
$this->publishedAt = new \DateTimeImmutable(); | ||
$this->comments = new ArrayCollection(); | ||
$this->tags = new ArrayCollection(); | ||
} | ||
|
@@ -162,12 +162,12 @@ public function setContent(string $content): void | |
$this->content = $content; | ||
} | ||
|
||
public function getPublishedAt(): \DateTime | ||
public function getPublishedAt(): \DateTimeInterface | ||
{ | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Should be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
{ | ||
$this->publishedAt = $publishedAt; | ||
} | ||
|
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
.