File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,13 @@ public static function isBlacklisted(string $email): bool
4141 $ parts = explode ('@ ' , $ email );
4242 $ domain = end ($ parts );
4343
44- foreach (self ::allDomainSuffixes ($ domain ) as $ domainSuffix ) {
44+ return self ::isDomainBlocked ($ domain , true );
45+ }
46+
47+ public static function isDomainBlocked (string $ domain , bool $ checkSubdomain ): bool
48+ {
49+ $ domainSuffixes = $ checkSubdomain ? self ::allDomainSuffixes ($ domain ) : [$ domain ];
50+ foreach ($ domainSuffixes as $ domainSuffix ) {
4551 if (isset (self ::$ blocklist [$ domainSuffix ])) {
4652 return true ;
4753 }
Original file line number Diff line number Diff line change @@ -64,8 +64,9 @@ public function testReturnFalseIfThrowableDomain()
6464
6565 public static function provideBlackListTests ()
6666 {
67- foreach (array_rand (MailChecker::blacklist (), 1000 ) as $ blacklistedDomain ) {
68- yield [$ blacklistedDomain ];
67+ $ blacklist = MailChecker::blacklist ();
68+ foreach (array_rand ($ blacklist , 1000 ) as $ key ) {
69+ yield [$ blacklist [$ key ]];
6970 }
7071 }
7172
@@ -90,4 +91,13 @@ public function testAddCustomDomains()
9091 $ this ->isInvalid ('foo@google.com ' );
9192 $ this ->isValid ('ok@gmail.com ' );
9293 }
94+
95+ #[DataProvider('provideBlackListTests ' )]
96+ public function testIsDomainBlocked ($ blacklistedDomain )
97+ {
98+ $ this ->assertEquals (true , MailChecker::isDomainBlocked ($ blacklistedDomain , true ));
99+ $ this ->assertEquals (true , MailChecker::isDomainBlocked ('subdomain. ' .$ blacklistedDomain , true ));
100+ $ this ->assertEquals (true , MailChecker::isDomainBlocked ($ blacklistedDomain , false ));
101+ $ this ->assertEquals (false , MailChecker::isDomainBlocked ('subdomain. ' .$ blacklistedDomain , false ));
102+ }
93103}
You can’t perform that action at this time.
0 commit comments