Completed
Branch BUG-10489-non-trashed-regs-onl... (a7561f)
by
unknown
46:07 queued 34:09
created

EmailAddress::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\domain\values;
4
5
use EventEspresso\core\domain\services\validation\email\EmailValidationException;
6
use EventEspresso\core\domain\services\validation\email\EmailValidatorInterface;
7
8
defined('EVENT_ESPRESSO_VERSION') || exit;
9
10
11
/**
12
 * Class EmailAddress
13
 * Value Object for representing a valid email address
14
 *
15
 * @package       EventEspresso\core\domain\values
16
 * @author        Brent Christensen
17
 * @since         $VID:$
18
 */
19
class EmailAddress
20
{
21
22
    /**
23
     * @var string $email_address
24
     */
25
    private $email_address;
26
27
28
29
    /**
30
     * EmailAddress constructor.
31
     *
32
     * @param string                  $email_address
33
     * @param EmailValidatorInterface $validator
34
     * @throws EmailValidationException
35
     */
36
    public function __construct($email_address, EmailValidatorInterface $validator)
37
    {
38
        $validator->validate($email_address);
39
        $this->email_address = $email_address;
40
    }
41
42
43
44
    /**
45
     * returns the string value for this EmailAddress
46
     *
47
     * @return string
48
     */
49
    public function get()
50
    {
51
        return $this->email_address;
52
    }
53
54
55
56
    /**
57
     * compare another EmailAddress to this one to determine if they are the same
58
     *
59
     * @param EmailAddress $address
60
     * @return bool
61
     */
62
    public function equals(EmailAddress $address)
63
    {
64
        return strtolower((string)$this) === strtolower((string)$address);
65
    }
66
67
68
    /**
69
     * allows an EmailAddress object to be used as a string
70
     *
71
     * @return string
72
     */
73
    public function __toString()
74
    {
75
        return $this->email_address;
76
    }
77
78
79
80
}
81
// Location: EmailAddress.php
82