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

@ -25,7 +25,7 @@ namespace App\Entity\LogSystem;
use Doctrine\DBAL\Types\Types;
use App\Entity\Base\AbstractDBElement;
use App\Entity\UserSystem\User;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\LogEntryRepository;
@ -56,10 +56,10 @@ abstract class AbstractLogEntry extends AbstractDBElement
protected string $username = '';
/**
* @var \DateTimeInterface The datetime the event associated with this log entry has occured
* @var \DateTimeImmutable The datetime the event associated with this log entry has occured
*/
#[ORM\Column(name: 'datetime', type: Types::DATETIME_MUTABLE)]
protected \DateTimeInterface $timestamp;
#[ORM\Column(name: 'datetime', type: Types::DATETIME_IMMUTABLE)]
protected \DateTimeImmutable $timestamp;
/**
* @var LogLevel The priority level of the associated level. 0 is highest, 7 lowest
@ -90,7 +90,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
public function __construct()
{
$this->timestamp = new DateTime();
$this->timestamp = new \DateTimeImmutable();
}
/**
@ -165,7 +165,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
/**
* Returns the timestamp when the event that caused this log entry happened.
*/
public function getTimestamp(): \DateTimeInterface
public function getTimestamp(): \DateTimeImmutable
{
return $this->timestamp;
}
@ -175,7 +175,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
*
* @return $this
*/
public function setTimestamp(\DateTime $timestamp): self
public function setTimestamp(\DateTimeImmutable $timestamp): self
{
$this->timestamp = $timestamp;