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

@ -183,9 +183,9 @@ class Category extends AbstractPartsContainingDBElement
protected Collection $parameters;
#[Groups(['category:read'])]
protected ?\DateTime $addedDate = null;
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['category:read'])]
protected ?\DateTime $lastModified = null;
protected ?\DateTimeImmutable $lastModified = null;
#[Assert\Valid]
#[ORM\Embedded(class: EDACategoryInfo::class)]

View file

@ -134,9 +134,9 @@ class Footprint extends AbstractPartsContainingDBElement
protected Collection $parameters;
#[Groups(['footprint:read'])]
protected ?\DateTime $addedDate = null;
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['footprint:read'])]
protected ?\DateTime $lastModified = null;
protected ?\DateTimeImmutable $lastModified = null;
#[Assert\Valid]
#[ORM\Embedded(class: EDAFootprintInfo::class)]

View file

@ -54,9 +54,9 @@ class InfoProviderReference
#[Groups(['provider_reference:read'])]
private ?string $provider_url = null;
#[Column(type: Types::DATETIME_MUTABLE, nullable: true, options: ['default' => null])]
#[Column(type: Types::DATETIME_IMMUTABLE, nullable: true, options: ['default' => null])]
#[Groups(['provider_reference:read'])]
private ?\DateTime $last_updated = null;
private ?\DateTimeImmutable $last_updated = null;
/**
* Constructing is forbidden from outside.
@ -95,9 +95,8 @@ class InfoProviderReference
/**
* Gets the time, when the part was last time updated by the provider.
* @return \DateTimeInterface|null
*/
public function getLastUpdated(): ?\DateTimeInterface
public function getLastUpdated(): ?\DateTimeImmutable
{
return $this->last_updated;
}
@ -140,7 +139,7 @@ class InfoProviderReference
$ref->provider_key = $provider_key;
$ref->provider_id = $provider_id;
$ref->provider_url = $provider_url;
$ref->last_updated = new \DateTime();
$ref->last_updated = new \DateTimeImmutable();
return $ref;
}
@ -155,7 +154,7 @@ class InfoProviderReference
$ref->provider_key = $dto->provider_key;
$ref->provider_id = $dto->provider_id;
$ref->provider_url = $dto->provider_url;
$ref->last_updated = new \DateTime();
$ref->last_updated = new \DateTimeImmutable();
return $ref;
}
}

View file

@ -156,9 +156,9 @@ class MeasurementUnit extends AbstractPartsContainingDBElement
protected Collection $parameters;
#[Groups(['measurement_unit:read'])]
protected ?\DateTime $addedDate = null;
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['measurement_unit:read'])]
protected ?\DateTime $lastModified = null;
protected ?\DateTimeImmutable $lastModified = null;
/**

View file

@ -154,9 +154,9 @@ class Part extends AttachmentContainingDBElement
protected ?Attachment $master_picture_attachment = null;
#[Groups(['part:read'])]
protected ?\DateTime $addedDate = null;
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['part:read'])]
protected ?\DateTime $lastModified = null;
protected ?\DateTimeImmutable $lastModified = null;
public function __construct()

View file

@ -105,13 +105,13 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
protected string $comment = '';
/**
* @var \DateTime|null Set a time until when the lot must be used.
* @var \DateTimeImmutable|null Set a time until when the lot must be used.
* Set to null, if the lot can be used indefinitely.
*/
#[Groups(['extended', 'full', 'import', 'part_lot:read', 'part_lot:write'])]
#[ORM\Column(name: 'expiration_date', type: Types::DATETIME_MUTABLE, nullable: true)]
#[ORM\Column(name: 'expiration_date', type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Year2038BugWorkaround]
protected ?\DateTime $expiration_date = null;
protected ?\DateTimeImmutable $expiration_date = null;
/**
* @var StorageLocation|null The storelocation of this lot
@ -194,7 +194,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
}
//Check if the expiration date is bigger then current time
return $this->expiration_date < new DateTime('now');
return $this->expiration_date < new \DateTimeImmutable('now');
}
/**
@ -236,7 +236,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
/**
* Gets the expiration date for the part lot. Returns null, if no expiration date was set.
*/
public function getExpirationDate(): ?\DateTimeInterface
public function getExpirationDate(): ?\DateTimeImmutable
{
return $this->expiration_date;
}
@ -246,7 +246,7 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
*
*
*/
public function setExpirationDate(?\DateTime $expiration_date): self
public function setExpirationDate(?\DateTimeImmutable $expiration_date): self
{
$this->expiration_date = $expiration_date;

View file

@ -170,9 +170,9 @@ class StorageLocation extends AbstractPartsContainingDBElement
protected ?Attachment $master_picture_attachment = null;
#[Groups(['location:read'])]
protected ?\DateTime $addedDate = null;
protected ?\DateTimeImmutable $addedDate = null;
#[Groups(['location:read'])]
protected ?\DateTime $lastModified = null;
protected ?\DateTimeImmutable $lastModified = null;
/********************************************************************************