From: Raphaƫl Gertz Date: Wed, 15 Sep 2021 15:32:12 +0000 (+0200) Subject: Handle null mail and password on new User entity X-Git-Tag: 0.2.0~2 X-Git-Url: https://git.rapsys.eu/userbundle/commitdiff_plain/0ac4d5b99450481d171b0f9ed2411a17c1dc873b Handle null mail and password on new User entity --- diff --git a/Entity/User.php b/Entity/User.php index 1e36a93..61be105 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -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; }