Completed
Branch FET-9222-rest-api-writes (b69541)
by
unknown
25:55 queued 14:06
created

InternationalDNS   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 28 3
1
<?php
2
3
namespace EventEspresso\core\services\validation\strategies;
4
5
use EventEspresso\core\domain\services\validation\EmailValidationException;
6
7
defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
8
9
10
11
/**
12
 * Class EmailValidationInternationalDNS
13
 * Validates the email in teh same way as the parent, but also
14
 * verifies the domain exists.
15
 *
16
 * @package        Event Espresso
17
 * @author         Mike Nelson
18
 * @since          $VID:$
19
 */
20
class InternationalDNS extends International
21
{
22
23
    /**
24
     * Validates the email in teh same way as the parent, but also
25
     * verifies the domain exists.
26
     * @param string $input
27
     * @return bool
28
     * @throws EmailValidationException
29
     */
30
    public function validate($input)
31
    {
32
        parent::validate($input);
33
        $domain = $this->getDomainPartOfEmail($input);
34
        if (! checkdnsrr($domain, "MX")) {
35
            // domain not found in MX records
36
            throw new EmailValidationException(
37
                __(
38
                    // @codingStandardsIgnoreStart
39
                    'Although the email address provided is formatted correctly, a valid "MX record" could not be located for that address and domain. Please enter a valid email address.',
40
                    // @codingStandardsIgnoreEnd
41
                    'event_espresso'
42
                )
43
            );
44
        }
45
        if (! checkdnsrr($domain, "A")) {
46
            // domain not found in A records
47
            throw new EmailValidationException(
48
                __(
49
                    // @codingStandardsIgnoreStart
50
                    'Although the email address provided is formatted correctly, a valid "A record" could not be located for that address and domain. Please enter a valid email address.',
51
                    // @codingStandardsIgnoreEnd
52
                    'event_espresso'
53
                )
54
            );
55
        }
56
        return true;
57
    }
58
}
59
// End of file EmailValidationInternationalDNS.php
60
// Location: core\services\validation/EmailValidationInternationalDNS.php