Skip to content

Commit 46cabfd

Browse files
committed
Use stricter DateTime type instead of DateTimeInterface for mutable datetime fields
1 parent dcd2260 commit 46cabfd

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/Doctrine/DoctrineHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public static function getPropertyTypeForColumn(string $columnType): ?string
264264
Types::BOOLEAN => 'bool',
265265
Types::INTEGER, Types::SMALLINT => 'int',
266266
Types::FLOAT => 'float',
267-
Types::DATETIME_MUTABLE, Types::DATETIMETZ_MUTABLE, Types::DATE_MUTABLE, Types::TIME_MUTABLE => '\\'.\DateTimeInterface::class,
267+
Types::DATETIME_MUTABLE, Types::DATETIMETZ_MUTABLE, Types::DATE_MUTABLE, Types::TIME_MUTABLE => '\\'.\DateTime::class,
268268
Types::DATETIME_IMMUTABLE, Types::DATETIMETZ_IMMUTABLE, Types::DATE_IMMUTABLE, Types::TIME_IMMUTABLE => '\\'.\DateTimeImmutable::class,
269269
Types::DATEINTERVAL => '\\'.\DateInterval::class,
270270
'object' => 'object',

tests/Util/fixtures/add_entity_field/User_simple_datetime.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Entity;
44

5-
use Doctrine\DBAL\Types\Types;
65
use Doctrine\ORM\Mapping as ORM;
76

87
#[ORM\Entity]
@@ -13,20 +12,20 @@ class User
1312
#[ORM\Column()]
1413
private ?int $id = null;
1514

16-
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
17-
private ?\DateTimeInterface $createdAt = null;
15+
#[ORM\Column(nullable: true)]
16+
private ?\DateTime $createdAt = null;
1817

1918
public function getId(): ?int
2019
{
2120
return $this->id;
2221
}
2322

24-
public function getCreatedAt(): ?\DateTimeInterface
23+
public function getCreatedAt(): ?\DateTime
2524
{
2625
return $this->createdAt;
2726
}
2827

29-
public function setCreatedAt(?\DateTimeInterface $createdAt): static
28+
public function setCreatedAt(?\DateTime $createdAt): static
3029
{
3130
$this->createdAt = $createdAt;
3231

0 commit comments

Comments
 (0)