<?phpnamespace App\Entity;use App\Repository\PasswordRecoveryRepository;use DateInterval;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: PasswordRecoveryRepository::class)]class PasswordRecovery{ const MAX_VALIDITY = 10; // Minutes #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\ManyToOne(inversedBy: 'passwordRecoveries')] #[ORM\JoinColumn(nullable: false)] private ?User $user = null; #[ORM\Column] private ?\DateTimeImmutable $createdAt = null; #[ORM\Column(length: 10)] private ?string $code = null; /** * @return int|null */ public function getId(): ?int { return $this->id; } /** * @return User|null */ public function getUser(): ?User { return $this->user; } /** * @param User|null $user * @return $this */ public function setUser(?User $user): static { $this->user = $user; return $this; } /** * @return \DateTimeImmutable|null */ public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } /** * @param \DateTimeImmutable $createdAt * @return $this */ public function setCreatedAt(\DateTimeImmutable $createdAt): static { $this->createdAt = $createdAt; return $this; } /** * @return string|null */ public function getCode(): ?string { return $this->code; } /** * @param string $code * @return $this */ public function setCode(string $code): static { $this->code = $code; return $this; } /** * @return bool * @throws \Exception */ public function isOutOfDate(): bool { $now = new \DateTime('now'); $diff = $now->diff($this->getCreatedAt()); return $diff->i > self::MAX_VALIDITY; }}