MxValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
dl 0
loc 16
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EmailValidator\Validator;
6
7
use EmailValidator\EmailAddress;
8
9
/**
10
 * Validates the MX records of an email domain
11
 *
12
 * This validator checks if the domain of an email address has valid MX records
13
 * configured, which is necessary for the domain to receive email. The validation
14
 * is only performed if enabled in the policy.
15
 */
16
class MxValidator extends AValidator
17
{
18
    /**
19
     * Validates the MX records of an email domain
20
     *
21
     * @param EmailAddress $email The email address to validate
22
     * @return bool True if MX records are valid or validation is disabled, false otherwise
23
     */
24
    public function validate(EmailAddress $email): bool
25
    {
26
        $valid = true;
27
        if ($this->policy->validateMxRecord()) {
28
            $domain = sprintf('%s.', $email->getDomain());
29
            $valid = checkdnsrr(idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46), 'MX');
30
        }
31
        return $valid;
32
    }
33
}
34