Use DatetimeImmutable instead of DateTime wherever possible

This commit is contained in:
Jan Böhmer 2024-06-22 17:36:54 +02:00
parent eebc373734
commit 235d572f8c
39 changed files with 222 additions and 112 deletions

View file

@ -156,9 +156,9 @@ class Currency extends AbstractStructuralDBElement
protected Collection $pricedetails;
#[Groups(['currency:read'])]
protected ?\DateTime $addedDate = null;
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['currency:read'])]
protected ?\DateTime $lastModified = null;
protected ?\DateTimeImmutable $lastModified = null;
public function __construct()

View file

@ -46,7 +46,7 @@ use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\Parts\Part;
use App\Entity\Parts\Supplier;
use DateTime;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -173,9 +173,9 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
#[ORM\PreUpdate]
public function updateTimestamps(): void
{
$this->lastModified = new DateTime('now');
$this->lastModified = new DateTimeImmutable('now');
if (!$this->addedDate instanceof \DateTimeInterface) {
$this->addedDate = new DateTime('now');
$this->addedDate = new DateTimeImmutable('now');
}
if ($this->part instanceof Part) {

View file

@ -38,7 +38,7 @@ use App\Validator\Constraints\BigDecimal\BigDecimalPositive;
use App\Validator\Constraints\Selectable;
use Brick\Math\BigDecimal;
use Brick\Math\RoundingMode;
use DateTime;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
@ -141,9 +141,9 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
#[ORM\PreUpdate]
public function updateTimestamps(): void
{
$this->lastModified = new DateTime('now');
$this->lastModified = new DateTimeImmutable('now');
if (!$this->addedDate instanceof \DateTimeInterface) {
$this->addedDate = new DateTime('now');
$this->addedDate = new DateTimeImmutable('now');
}
if ($this->orderdetail instanceof Orderdetail) {