]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Entity/User.php
Replace deprecated DateTime by DateTimeImmutable
[userbundle] / Entity / User.php
index 380c7ffa1660b83a53fdbd9ab3ed88e65c1d4670..82cbcff10b7193e54dea8a07e2a4aceb64f3fae0 100644 (file)
@@ -15,33 +15,33 @@ use Doctrine\Common\Collections\Collection;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\ORM\Event\PreUpdateEventArgs;
 
-use Symfony\Component\Security\Core\User\UserInterface;
-use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
-
 use Rapsys\UserBundle\Entity\Civility;
 use Rapsys\UserBundle\Entity\Group;
 
+use Symfony\Component\Security\Core\User\UserInterface;
+use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
+
 /**
  * User
  */
 class User implements UserInterface, PasswordAuthenticatedUserInterface {
        /**
-        * @var ?integer
+        * Primary key
         */
-       protected ?int $id;
+       protected ?int $id = null;
 
        /**
-        * @var \DateTime
+        * Create datetime
         */
-       protected \DateTime $created;
+       protected \DateTimeImmutable $created;
 
        /**
-        * @var \DateTime
+        * Update datetime
         */
-       protected \DateTime $updated;
+       protected \DateTimeImmutable $updated;
 
        /**
-        * @var Doctrine\Common\Collections\Collection
+        * Groups collection
         */
        protected Collection $groups;
 
@@ -58,8 +58,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface {
         */
        public function __construct(protected string $mail, protected string $password, protected ?Civility $civility = null, protected ?string $forename = null, protected ?string $surname = null, protected bool $active = false, protected bool $enable = true) {
                //Set defaults
-               $this->created = new \DateTime('now');
-               $this->updated = new \DateTime('now');
+               $this->created = new \DateTimeImmutable('now');
+               $this->updated = new \DateTimeImmutable('now');
 
                //Set collections
                $this->groups = new ArrayCollection();
@@ -212,11 +212,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface {
        /**
         * Set created
         *
-        * @param \DateTime $created
+        * @param \DateTimeImmutable $created
         *
         * @return User
         */
-       public function setCreated(\DateTime $created): User {
+       public function setCreated(\DateTimeImmutable $created): User {
                $this->created = $created;
 
                return $this;
@@ -225,9 +225,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface {
        /**
         * Get created
         *
-        * @return \DateTime
+        * @return \DateTimeImmutable
         */
-       public function getCreated(): \DateTime {
+       public function getCreated(): \DateTimeImmutable {
                return $this->created;
        }