From 1061914a5f91f6379fbf7acf2ced569857e82930 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Sun, 7 Jun 2020 19:26:15 +0800 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD=20tr?= =?UTF-8?q?ait=20HasEmail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * valid_strlen() * Constraints::MAX_LENGTH_EMAIL * phpdoc --- src/AtolOnline/Traits/HasEmail.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/AtolOnline/Traits/HasEmail.php b/src/AtolOnline/Traits/HasEmail.php index c65f211..9254327 100644 --- a/src/AtolOnline/Traits/HasEmail.php +++ b/src/AtolOnline/Traits/HasEmail.php @@ -9,7 +9,7 @@ namespace AtolOnline\Traits; -use AtolOnline\{Exceptions\AtolEmailTooLongException, Exceptions\AtolEmailValidateException}; +use AtolOnline\{Constants\Constraints, Exceptions\AtolEmailTooLongException, Exceptions\AtolEmailValidateException}; /** * Добавляет объекту функционал для работы с email @@ -38,16 +38,15 @@ trait HasEmail * * @param string $email * @return $this - * @throws AtolEmailTooLongException - * @throws AtolEmailValidateException + * @throws \AtolOnline\Exceptions\AtolEmailTooLongException Слишком длинный email + * @throws \AtolOnline\Exceptions\AtolEmailValidateException Невалидный email */ public function setEmail(string $email) { $email = trim($email); - if ((function_exists('mb_strlen') ? mb_strlen($email) : strlen($email)) > 64) { - throw new AtolEmailTooLongException($email, 64); - } - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + if (valid_strlen($email) > Constraints::MAX_LENGTH_EMAIL) { + throw new AtolEmailTooLongException($email, Constraints::MAX_LENGTH_EMAIL); + } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new AtolEmailValidateException($email); } $this->email = $email;