From 80391cd9dd361e0d23d67131d48325a3c8a7a34d Mon Sep 17 00:00:00 2001 From: Mariusz Date: Fri, 9 Sep 2022 22:33:58 +0200 Subject: [PATCH 1/4] create a factory for email validator --- src/EmailValidatorFactory.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/EmailValidatorFactory.php diff --git a/src/EmailValidatorFactory.php b/src/EmailValidatorFactory.php new file mode 100644 index 0000000..662467e --- /dev/null +++ b/src/EmailValidatorFactory.php @@ -0,0 +1,35 @@ +isValid($emailAddress, $multipleValidations); + } +} \ No newline at end of file From ea83c820cc12822cdd173f7ebd88f0ab7a4f2763 Mon Sep 17 00:00:00 2001 From: Mariusz Date: Fri, 9 Sep 2022 22:45:19 +0200 Subject: [PATCH 2/4] return in an array with the specified name --- src/EmailValidatorFactory.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/EmailValidatorFactory.php b/src/EmailValidatorFactory.php index 662467e..08e802d 100644 --- a/src/EmailValidatorFactory.php +++ b/src/EmailValidatorFactory.php @@ -6,30 +6,34 @@ use Egulias\EmailValidator\Validation\DNSCheckValidation; use Egulias\EmailValidator\Validation\DNSGetRecordWrapper; -use Egulias\EmailValidator\Validation\DNSRecords; use Egulias\EmailValidator\Validation\MessageIDValidation; -use Egulias\EmailValidator\Validation\MultipleValidationWithAnd; use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; use Egulias\EmailValidator\Validation\RFCValidation; class EmailValidatorFactory { + /** @var Validator[] */ + protected static array $defaultValidators = [ + RFCValidation::class, + NoRFCWarningsValidation::class, + MessageIDValidation::class, + DNSGetRecordWrapper::class, + DNSCheckValidation::class + ]; + /** * @param string $emailAddress - * @return bool + * @return array */ - public static function create(string $emailAddress): bool + public static function create(string $emailAddress): array { $validator = new EmailValidator(); + $result = []; - $multipleValidations = new MultipleValidationWithAnd([ - new RFCValidation(), - new NoRFCWarningsValidation(), - new MessageIDValidation(), - new DNSGetRecordWrapper(), - new DNSCheckValidation() - ]); + foreach (self::$defaultValidators as $key => $val) { + $result[get_class(new $val)] = $validator->isValid($emailAddress, new $val); + } - return $validator->isValid($emailAddress, $multipleValidations); + return $result; } } \ No newline at end of file From 195cba1b9d0776f970bc9ad4278630406efaeea3 Mon Sep 17 00:00:00 2001 From: Mariusz Date: Fri, 9 Sep 2022 22:45:40 +0200 Subject: [PATCH 3/4] clean code --- src/EmailValidatorFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EmailValidatorFactory.php b/src/EmailValidatorFactory.php index 08e802d..df1bc6b 100644 --- a/src/EmailValidatorFactory.php +++ b/src/EmailValidatorFactory.php @@ -12,7 +12,7 @@ class EmailValidatorFactory { - /** @var Validator[] */ + /** @var [] */ protected static array $defaultValidators = [ RFCValidation::class, NoRFCWarningsValidation::class, From 20cc04914ae96e718e0e7018290aae82e56805ee Mon Sep 17 00:00:00 2001 From: Mariusz Date: Sat, 10 Sep 2022 08:15:15 +0200 Subject: [PATCH 4/4] Update EmailValidatorFactory.php --- src/EmailValidatorFactory.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/EmailValidatorFactory.php b/src/EmailValidatorFactory.php index df1bc6b..5a0a108 100644 --- a/src/EmailValidatorFactory.php +++ b/src/EmailValidatorFactory.php @@ -4,9 +4,8 @@ namespace Egulias\EmailValidator; +use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Validation\DNSCheckValidation; -use Egulias\EmailValidator\Validation\DNSGetRecordWrapper; -use Egulias\EmailValidator\Validation\MessageIDValidation; use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; use Egulias\EmailValidator\Validation\RFCValidation; @@ -16,8 +15,6 @@ class EmailValidatorFactory protected static array $defaultValidators = [ RFCValidation::class, NoRFCWarningsValidation::class, - MessageIDValidation::class, - DNSGetRecordWrapper::class, DNSCheckValidation::class ]; @@ -36,4 +33,4 @@ public static function create(string $emailAddress): array return $result; } -} \ No newline at end of file +}