]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Entity/User.php
Strict types
[userbundle] / Entity / User.php
index a56518768910a46ea17fc057b0c579e875a24ee1..44680fb360729496577dce4fa4860498090a0093 100644 (file)
@@ -14,6 +14,7 @@ namespace Rapsys\UserBundle\Entity;
 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;
 
@@ -25,57 +26,22 @@ use Rapsys\UserBundle\Entity\Group;
  */
 class User implements UserInterface, PasswordAuthenticatedUserInterface {
        /**
-        * @var ?integer
+        * Primary key
         */
-       protected ?int $id;
+       protected ?int $id = null;
 
        /**
-        * @var string
-        */
-       protected string $mail;
-
-       /**
-        * @var string
-        */
-       protected string $password;
-
-       /**
-        * @var ?string
-        */
-       protected ?string $forename;
-
-       /**
-        * @var ?string
-        */
-       protected ?string $surname;
-
-       /**
-        * @var bool
-        */
-       protected bool $active;
-
-       /**
-        * @var bool
-        */
-       protected bool $enable;
-
-       /**
-        * @var \DateTime
+        * Creation datetime
         */
        protected \DateTime $created;
 
        /**
-        * @var \DateTime
+        * Update datetime
         */
        protected \DateTime $updated;
 
        /**
-        * @var Civility
-        */
-       protected ?Civility $civility;
-
-       /**
-        * @var Doctrine\Common\Collections\Collection
+        * Groups collection
         */
        protected Collection $groups;
 
@@ -90,15 +56,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface {
         * @param bool $active The user active
         * @param bool $enable The user enable
         */
-       public function __construct(string $mail, string $password, ?Civility $civility = null, ?string $forename = null, ?string $surname = null, bool $active = false, bool $enable = true) {
+       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->mail = $mail;
-               $this->password = $password;
-               $this->civility = $civility;
-               $this->forename = $forename;
-               $this->surname = $surname;
-               $this->active = $active;
-               $this->enable = $enable;
                $this->created = new \DateTime('now');
                $this->updated = new \DateTime('now');
 
@@ -196,10 +155,10 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface {
        }
 
        /**
-        * Get password
-        *
         * {@inheritdoc}
         *
+        * Get password
+        *
         * @return string
         */
        public function getPassword(): string {
@@ -357,7 +316,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface {
                                return $array;
                        },
                        //Init with empty array
-                       //XXX: on registration, add each group present in rapsys_user.default.group array to user
+                       //XXX: on registration, add each group present in rapsysuser.default.group array to user
                        //XXX: see vendor/rapsys/userbundle/Controller/DefaultController.php +450
                        []
                ));
@@ -474,7 +433,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface {
         */
        public function preUpdate(PreUpdateEventArgs $eventArgs) {
                //Check that we have an user instance
-               if (($user = $eventArgs->getEntity()) instanceof User) {
+               if (($user = $eventArgs->getObject()) instanceof User) {
                        //Set updated value
                        $user->setUpdated(new \DateTime('now'));
                }