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

EmailAddress   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 4 1
A equals() 0 4 1
A __toString() 0 4 1
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