From 8d91d7adb3debe9a6ae4a30125a77b8ea2de0ba1 Mon Sep 17 00:00:00 2001 From: Jan Lam Date: Mon, 14 Sep 2026 14:11:56 +0200 Subject: [PATCH] Use DateTime, to match what the accessor-generator-plugin-lib generates --- README.md | 10 +++++----- composer.json | 3 +++ src/BlamableInterface.php | 4 ++-- src/Provider/BlamableProviderInterface.php | 2 +- test/Listener/EntityWithAttribute.php | 14 +++++++------- test/Listener/EntityWithInterfaceOnly.php | 14 +++++++------- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 6b74eb7..c33719a 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ class AcmeBlamableProvider implements BlamableProviderInterface return $this->username; } - public function getChangedAt(): \DateTimeInterface + public function getChangedAt(): \DateTime { return new \DateTimeImmutable(); } @@ -152,10 +152,10 @@ class MyEntity implements BlamableInterface private ?string $updated_by = null; #[ORM\Column(type: 'datetime_immutable', nullable: true)] - private ?\DateTimeInterface $updated_at = null; + private ?\DateTime $updated_at = null; #[ORM\Column(type: 'datetime_immutable', nullable: true)] - private ?\DateTimeInterface $created_at = null; + private ?\DateTime $created_at = null; public function setUpdatedBy(string $by): static { @@ -164,14 +164,14 @@ class MyEntity implements BlamableInterface return $this; } - public function setUpdatedAt(\DateTimeInterface $at): static + public function setUpdatedAt(\DateTime $at): static { $this->updated_at = $at; return $this; } - public function setCreatedAt(\DateTimeInterface $at): static + public function setCreatedAt(\DateTime $at): static { $this->created_at = $at; diff --git a/composer.json b/composer.json index b567133..987a72b 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,9 @@ "hostnet/phpcs-tool": "^9.1.0", "phpunit/phpunit": "^9.5.6" }, + "conflict": { + "hostnet/entity-plugin-lib": "<4.1.0" + }, "autoload": { "psr-4": { "Hostnet\\Component\\EntityBlamable\\": "src/" diff --git a/src/BlamableInterface.php b/src/BlamableInterface.php index 99a063f..873fb17 100644 --- a/src/BlamableInterface.php +++ b/src/BlamableInterface.php @@ -13,7 +13,7 @@ interface BlamableInterface { public function setUpdatedBy(string $by): static; - public function setUpdatedAt(\DateTimeInterface $at): static; + public function setUpdatedAt(\DateTime $at): static; - public function setCreatedAt(\DateTimeInterface $at): static; + public function setCreatedAt(\DateTime $at): static; } diff --git a/src/Provider/BlamableProviderInterface.php b/src/Provider/BlamableProviderInterface.php index 9392880..1a68c1e 100644 --- a/src/Provider/BlamableProviderInterface.php +++ b/src/Provider/BlamableProviderInterface.php @@ -10,5 +10,5 @@ interface BlamableProviderInterface { public function getUpdatedBy(): string; - public function getChangedAt(): \DateTimeInterface; + public function getChangedAt(): \DateTime; } diff --git a/test/Listener/EntityWithAttribute.php b/test/Listener/EntityWithAttribute.php index c7138ab..4d29621 100644 --- a/test/Listener/EntityWithAttribute.php +++ b/test/Listener/EntityWithAttribute.php @@ -12,10 +12,10 @@ #[Blamable] class EntityWithAttribute implements BlamableInterface { - private ?\DateTimeInterface $created_at = null; + private ?\DateTime $created_at = null; - private ?string $updated_by = null; - private ?\DateTimeInterface $updated_at = null; + private ?string $updated_by = null; + private ?\DateTime $updated_at = null; public function setUpdatedBy(string $by): static { @@ -29,26 +29,26 @@ public function getUpdatedBy(): ?string return $this->updated_by; } - public function setUpdatedAt(\DateTimeInterface $at): static + public function setUpdatedAt(\DateTime $at): static { $this->updated_at = $at; return $this; } - public function getUpdatedAt(): ?\DateTimeInterface + public function getUpdatedAt(): ?\DateTime { return $this->updated_at; } - public function setCreatedAt(\DateTimeInterface $at): static + public function setCreatedAt(\DateTime $at): static { $this->created_at = $at; return $this; } - public function getCreatedAt(): ?\DateTimeInterface + public function getCreatedAt(): ?\DateTime { return $this->created_at; } diff --git a/test/Listener/EntityWithInterfaceOnly.php b/test/Listener/EntityWithInterfaceOnly.php index 6dc9e5b..6d23012 100644 --- a/test/Listener/EntityWithInterfaceOnly.php +++ b/test/Listener/EntityWithInterfaceOnly.php @@ -10,10 +10,10 @@ class EntityWithInterfaceOnly implements BlamableInterface { - private ?\DateTimeInterface $created_at = null; + private ?\DateTime $created_at = null; - private ?string $updated_by = null; - private ?\DateTimeInterface $updated_at = null; + private ?string $updated_by = null; + private ?\DateTime $updated_at = null; public function setUpdatedBy(string $by): static { @@ -27,26 +27,26 @@ public function getUpdatedBy(): ?string return $this->updated_by; } - public function setUpdatedAt(\DateTimeInterface $at): static + public function setUpdatedAt(\DateTime $at): static { $this->updated_at = $at; return $this; } - public function getUpdatedAt(): ?\DateTimeInterface + public function getUpdatedAt(): ?\DateTime { return $this->updated_at; } - public function setCreatedAt(\DateTimeInterface $at): static + public function setCreatedAt(\DateTime $at): static { $this->created_at = $at; return $this; } - public function getCreatedAt(): ?\DateTimeInterface + public function getCreatedAt(): ?\DateTime { return $this->created_at; }