BannedListValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EmailValidator\Validator;
6
7
use EmailValidator\EmailAddress;
8
9
/**
10
 * Validates email addresses against a list of banned domains
11
 *
12
 * This validator checks if the domain of an email address is in a list of banned domains.
13
 * The validation is only performed if enabled in the policy. Domain matching supports
14
 * wildcard patterns for flexible banning rules.
15
 */
16
class BannedListValidator extends AValidator
17
{
18
    /**
19
     * Validates an email address against the banned domains list
20
     *
21
     * @param EmailAddress $email The email address to validate
22
     * @return bool True if the domain is not banned or validation is disabled, false if the domain is banned
23
     */
24
    public function validate(EmailAddress $email): bool
25
    {
26
        if ($this->policy->checkBannedListedEmail()) {
27
            $domain = $email->getDomain();
28
            foreach ($this->policy->getBannedList() as $bannedDomain) {
29
                if (fnmatch($bannedDomain, $domain ?? '')) {
30
                    return false;
31
                }
32
            }
33
        }
34
        return true;
35
    }
36
}
37