]> Raphaël G. Git Repositories - userbundle/commitdiff
Handle null mail and password on new User entity
authorRaphaël Gertz <git@rapsys.eu>
Wed, 15 Sep 2021 15:32:12 +0000 (17:32 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Wed, 15 Sep 2021 15:32:12 +0000 (17:32 +0200)
Entity/User.php

index 1e36a931b364da2678c99123ec557333bc752668..61be1051684af4a8e533d809413d1aa558eb3c9b 100644 (file)
@@ -81,13 +81,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
        /**
         * Constructor
         *
        /**
         * Constructor
         *
-        * @param string $mail The user mail
+        * @param ?string $mail The user mail
         */
         */
-       public function __construct(string $mail) {
+       public function __construct(?string $mail) {
                //With mail
                //With mail
-               if (!empty($this->mail = $mail)) {
+               if ($mail !== null && !empty($mail)) {
+                       $this->mail = $mail;
                        $this->password = $mail;
                        $this->password = $mail;
+               //Without mail
                } else {
                } else {
+                       $this->mail = '';
                        $this->password = '';
                }
 
                        $this->password = '';
                }
 
@@ -115,18 +118,23 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
        /**
         * Set mail
         *
        /**
         * Set mail
         *
-        * @param string $mail
-        *
+        * @param ?string $mail
         * @return User
         */
         * @return User
         */
-       public function setMail(string $mail): User {
+       public function setMail(?string $mail): User {
                //With mail
                //With mail
-               if (!empty($this->mail = $mail)) {
+               if ($mail !== null && !empty($mail)) {
+                       //Set mail
+                       $this->mail = $mail;
+
                        //Without password
                        if (empty($this->password)) {
                                //Set mail as password
                                $this->password = $mail;
                        }
                        //Without password
                        if (empty($this->password)) {
                                //Set mail as password
                                $this->password = $mail;
                        }
+               //Without mail
+               } else {
+                       $this->mail = '';
                }
 
                return $this;
                }
 
                return $this;
@@ -192,8 +200,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
         *
         * @return User
         */
         *
         * @return User
         */
-       public function setPassword(string $password): User {
-               $this->password = $password;
+       public function setPassword(?string $password): User {
+               //With password
+               if ($password !== null && !empty($password)) {
+                       $this->password = $password;
+               //Without password
+               } else {
+                       $this->password = '';
+               }
 
                return $this;
        }
 
                return $this;
        }
@@ -205,7 +219,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
         *
         * @return string
         */
         *
         * @return string
         */
-       public function getPassword(): ?string {
+       public function getPassword(): string {
                return $this->password;
        }
 
                return $this->password;
        }