src/Entity/PasswordRecovery.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PasswordRecoveryRepository;
  4. use DateInterval;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClassPasswordRecoveryRepository::class)]
  7. class PasswordRecovery
  8. {
  9.     const MAX_VALIDITY 10// Minutes
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\ManyToOne(inversedBy'passwordRecoveries')]
  15.     #[ORM\JoinColumn(nullablefalse)]
  16.     private ?User $user null;
  17.     #[ORM\Column]
  18.     private ?\DateTimeImmutable $createdAt null;
  19.     #[ORM\Column(length10)]
  20.     private ?string $code null;
  21.     /**
  22.      * @return int|null
  23.      */
  24.     public function getId(): ?int
  25.     {
  26.         return $this->id;
  27.     }
  28.     /**
  29.      * @return User|null
  30.      */
  31.     public function getUser(): ?User
  32.     {
  33.         return $this->user;
  34.     }
  35.     /**
  36.      * @param User|null $user
  37.      * @return $this
  38.      */
  39.     public function setUser(?User $user): static
  40.     {
  41.         $this->user $user;
  42.         return $this;
  43.     }
  44.     /**
  45.      * @return \DateTimeImmutable|null
  46.      */
  47.     public function getCreatedAt(): ?\DateTimeImmutable
  48.     {
  49.         return $this->createdAt;
  50.     }
  51.     /**
  52.      * @param \DateTimeImmutable $createdAt
  53.      * @return $this
  54.      */
  55.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  56.     {
  57.         $this->createdAt $createdAt;
  58.         return $this;
  59.     }
  60.     /**
  61.      * @return string|null
  62.      */
  63.     public function getCode(): ?string
  64.     {
  65.         return $this->code;
  66.     }
  67.     /**
  68.      * @param string $code
  69.      * @return $this
  70.      */
  71.     public function setCode(string $code): static
  72.     {
  73.         $this->code $code;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return bool
  78.      * @throws \Exception
  79.      */
  80.     public function isOutOfDate(): bool
  81.     {
  82.         $now = new \DateTime('now');
  83.         $diff $now->diff($this->getCreatedAt());
  84.         return $diff->self::MAX_VALIDITY;
  85.     }
  86. }