]> Raphaƫl G. Git Repositories - userbundle/blobdiff - Entity/User.php
Add contribute
[userbundle] / Entity / User.php
index 1e36a931b364da2678c99123ec557333bc752668..8103ea6bcd111d26ad5592eb046022f5ce3ed89e 100644 (file)
@@ -22,7 +22,7 @@ use Rapsys\UserBundle\Entity\Group;
 /**
  * User
  */
-class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable {
+class User implements UserInterface, PasswordAuthenticatedUserInterface {
        /**
         * @var integer
         */
@@ -81,13 +81,16 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
        /**
         * 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
-               if (!empty($this->mail = $mail)) {
+               if ($mail !== null && !empty($mail)) {
+                       $this->mail = $mail;
                        $this->password = $mail;
+               //Without mail
                } else {
+                       $this->mail = '';
                        $this->password = '';
                }
 
@@ -115,18 +118,23 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
        /**
         * Set mail
         *
-        * @param string $mail
-        *
+        * @param ?string $mail
         * @return User
         */
-       public function setMail(string $mail): User {
+       public function setMail(?string $mail): User {
                //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 mail
+               } else {
+                       $this->mail = '';
                }
 
                return $this;
@@ -192,8 +200,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
         *
         * @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;
        }
@@ -205,7 +219,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
         *
         * @return string
         */
-       public function getPassword(): ?string {
+       public function getPassword(): string {
                return $this->password;
        }
 
@@ -421,8 +435,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
        /**
         * {@inheritdoc}
         */
-       public function serialize(): string {
-               return serialize([
+       public function __serialize(): array {
+               return [
                        $this->id,
                        $this->mail,
                        $this->forename,
@@ -432,13 +446,13 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
                        $this->disabled,
                        $this->created,
                        $this->updated
-               ]);
+               ];
        }
 
        /**
         * {@inheritdoc}
         */
-       public function unserialize($serialized) {
+       public function __unserialize(array $data): void {
                list(
                        $this->id,
                        $this->mail,
@@ -449,7 +463,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serial
                        $this->disabled,
                        $this->created,
                        $this->updated
-               ) = unserialize($serialized);
+               ) = $data;
        }
 
        /**