@@ -25,40 +25,40 @@ |
||
25 | 25 | class Recipients extends ArrayCollection |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Instantiate a Recipients object. |
|
30 | - * |
|
31 | - * @param array $emails Array of email addresses and/or recipients. |
|
32 | - */ |
|
33 | - public function __construct(array $emails) |
|
34 | - { |
|
35 | - parent::__construct([]); |
|
36 | - $this->add($emails); |
|
37 | - } |
|
28 | + /** |
|
29 | + * Instantiate a Recipients object. |
|
30 | + * |
|
31 | + * @param array $emails Array of email addresses and/or recipients. |
|
32 | + */ |
|
33 | + public function __construct(array $emails) |
|
34 | + { |
|
35 | + parent::__construct([]); |
|
36 | + $this->add($emails); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Add an email address to the Recipients collection. |
|
41 | - * |
|
42 | - * @param Recipients|EmailAddress|array|string $email Email address to add. |
|
43 | - * |
|
44 | - * @return static |
|
45 | - */ |
|
46 | - public function add($email) |
|
47 | - { |
|
48 | - if ($email instanceof EmailAddress) { |
|
49 | - parent::add($email); |
|
39 | + /** |
|
40 | + * Add an email address to the Recipients collection. |
|
41 | + * |
|
42 | + * @param Recipients|EmailAddress|array|string $email Email address to add. |
|
43 | + * |
|
44 | + * @return static |
|
45 | + */ |
|
46 | + public function add($email) |
|
47 | + { |
|
48 | + if ($email instanceof EmailAddress) { |
|
49 | + parent::add($email); |
|
50 | 50 | |
51 | - return $this; |
|
52 | - } |
|
51 | + return $this; |
|
52 | + } |
|
53 | 53 | |
54 | - if (is_array($email) || $email instanceof Recipients) { |
|
55 | - array_walk($email, [$this, 'add']); |
|
54 | + if (is_array($email) || $email instanceof Recipients) { |
|
55 | + array_walk($email, [$this, 'add']); |
|
56 | 56 | |
57 | - return $this; |
|
58 | - } |
|
57 | + return $this; |
|
58 | + } |
|
59 | 59 | |
60 | - parent::add(new EmailAddress($email)); |
|
60 | + parent::add(new EmailAddress($email)); |
|
61 | 61 | |
62 | - return $this; |
|
63 | - } |
|
62 | + return $this; |
|
63 | + } |
|
64 | 64 | } |
65 | 65 | \ No newline at end of file |
@@ -25,96 +25,96 @@ |
||
25 | 25 | class EmailAddress |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * The local part of the email address (before the '@' sign). |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $localPart; |
|
28 | + /** |
|
29 | + * The local part of the email address (before the '@' sign). |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $localPart; |
|
34 | 34 | |
35 | - /** |
|
36 | - * The domain part of the email address (after the '@' sign). |
|
37 | - * |
|
38 | - * @var Domain |
|
39 | - */ |
|
40 | - protected $domain; |
|
35 | + /** |
|
36 | + * The domain part of the email address (after the '@' sign). |
|
37 | + * |
|
38 | + * @var Domain |
|
39 | + */ |
|
40 | + protected $domain; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Instantiate an EmailAddress object. |
|
44 | - * |
|
45 | - * @param EmailAddress|string $email The email to parse. |
|
46 | - * |
|
47 | - * @throws InvalidEmailAddress If the email is not valid. |
|
48 | - */ |
|
49 | - public function __construct($email) |
|
50 | - { |
|
51 | - if ($email instanceof EmailAddress) { |
|
52 | - $this->localPart = $email->getLocalPart(); |
|
53 | - $this->domain = $email->getDomain(); |
|
54 | - } else { |
|
55 | - if ( ! $this->isValid($email)) { |
|
56 | - throw InvalidEmailAddress::from($email); |
|
57 | - } |
|
42 | + /** |
|
43 | + * Instantiate an EmailAddress object. |
|
44 | + * |
|
45 | + * @param EmailAddress|string $email The email to parse. |
|
46 | + * |
|
47 | + * @throws InvalidEmailAddress If the email is not valid. |
|
48 | + */ |
|
49 | + public function __construct($email) |
|
50 | + { |
|
51 | + if ($email instanceof EmailAddress) { |
|
52 | + $this->localPart = $email->getLocalPart(); |
|
53 | + $this->domain = $email->getDomain(); |
|
54 | + } else { |
|
55 | + if ( ! $this->isValid($email)) { |
|
56 | + throw InvalidEmailAddress::from($email); |
|
57 | + } |
|
58 | 58 | |
59 | - try { |
|
60 | - $parts = explode('@', $email); |
|
61 | - $this->localPart = trim($parts[0]); |
|
62 | - $this->domain = new Domain(trim($parts[1])); |
|
63 | - } catch (Exception $exception) { |
|
64 | - throw InvalidEmailAddress::from($email); |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
59 | + try { |
|
60 | + $parts = explode('@', $email); |
|
61 | + $this->localPart = trim($parts[0]); |
|
62 | + $this->domain = new Domain(trim($parts[1])); |
|
63 | + } catch (Exception $exception) { |
|
64 | + throw InvalidEmailAddress::from($email); |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Returns the local part of the email address. |
|
71 | - * |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function getLocalPart() |
|
75 | - { |
|
76 | - return $this->localPart; |
|
77 | - } |
|
69 | + /** |
|
70 | + * Returns the local part of the email address. |
|
71 | + * |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function getLocalPart() |
|
75 | + { |
|
76 | + return $this->localPart; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Returns the domain part of the email address. |
|
81 | - * |
|
82 | - * @return Domain |
|
83 | - */ |
|
84 | - public function getDomain() |
|
85 | - { |
|
86 | - return $this->domain; |
|
87 | - } |
|
79 | + /** |
|
80 | + * Returns the domain part of the email address. |
|
81 | + * |
|
82 | + * @return Domain |
|
83 | + */ |
|
84 | + public function getDomain() |
|
85 | + { |
|
86 | + return $this->domain; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Returns the entire email address. |
|
91 | - * |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function getAddress() |
|
95 | - { |
|
96 | - return $this->getLocalPart() . '@' . $this->getDomain(); |
|
97 | - } |
|
89 | + /** |
|
90 | + * Returns the entire email address. |
|
91 | + * |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function getAddress() |
|
95 | + { |
|
96 | + return $this->getLocalPart() . '@' . $this->getDomain(); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Convert the EmailAddress object to a string. |
|
101 | - * |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function __toString() |
|
105 | - { |
|
106 | - return $this->getAddress(); |
|
107 | - } |
|
99 | + /** |
|
100 | + * Convert the EmailAddress object to a string. |
|
101 | + * |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function __toString() |
|
105 | + { |
|
106 | + return $this->getAddress(); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Check whether an email is valid. |
|
111 | - * |
|
112 | - * @param string $email Email to check. |
|
113 | - * |
|
114 | - * @return bool Whether the email is valid. |
|
115 | - */ |
|
116 | - protected function isValid($email) |
|
117 | - { |
|
118 | - return (bool)filter_var($email, FILTER_VALIDATE_EMAIL); |
|
119 | - } |
|
109 | + /** |
|
110 | + * Check whether an email is valid. |
|
111 | + * |
|
112 | + * @param string $email Email to check. |
|
113 | + * |
|
114 | + * @return bool Whether the email is valid. |
|
115 | + */ |
|
116 | + protected function isValid($email) |
|
117 | + { |
|
118 | + return (bool)filter_var($email, FILTER_VALIDATE_EMAIL); |
|
119 | + } |
|
120 | 120 | } |
121 | 121 | \ No newline at end of file |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getAddress() |
95 | 95 | { |
96 | - return $this->getLocalPart() . '@' . $this->getDomain(); |
|
96 | + return $this->getLocalPart().'@'.$this->getDomain(); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -115,6 +115,6 @@ discard block |
||
115 | 115 | */ |
116 | 116 | protected function isValid($email) |
117 | 117 | { |
118 | - return (bool)filter_var($email, FILTER_VALIDATE_EMAIL); |
|
118 | + return (bool) filter_var($email, FILTER_VALIDATE_EMAIL); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | \ No newline at end of file |