Use stricter DateTime type instead of DateTimeInterface for mutable datetime fields

This commit is contained in:
Jan Rosier
2025-02-05 21:43:35 +01:00
committed by Kevin Bond
parent e23699451e
commit e80aa170e0
2 changed files with 5 additions and 6 deletions

View File

@@ -263,7 +263,7 @@ final class DoctrineHelper
Types::BOOLEAN => 'bool',
Types::INTEGER, Types::SMALLINT => 'int',
Types::FLOAT => 'float',
Types::DATETIME_MUTABLE, Types::DATETIMETZ_MUTABLE, Types::DATE_MUTABLE, Types::TIME_MUTABLE => '\\'.\DateTimeInterface::class,
Types::DATETIME_MUTABLE, Types::DATETIMETZ_MUTABLE, Types::DATE_MUTABLE, Types::TIME_MUTABLE => '\\'.\DateTime::class,
Types::DATETIME_IMMUTABLE, Types::DATETIMETZ_IMMUTABLE, Types::DATE_IMMUTABLE, Types::TIME_IMMUTABLE => '\\'.\DateTimeImmutable::class,
Types::DATEINTERVAL => '\\'.\DateInterval::class,
'object' => 'object',

View File

@@ -2,7 +2,6 @@
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
@@ -13,20 +12,20 @@ class User
#[ORM\Column()]
private ?int $id = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $createdAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTime $createdAt = null;
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeInterface
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): static
public function setCreatedAt(?\DateTime $createdAt): static
{
$this->createdAt = $createdAt;