diff --git a/lib/mail/EmailAddress.php b/lib/mail/EmailAddress.php index eccffabfd..084cea0ac 100644 --- a/lib/mail/EmailAddress.php +++ b/lib/mail/EmailAddress.php @@ -25,7 +25,9 @@ class EmailAddress implements \JsonSerializable private $name; /** @var $email string The email address */ private $email; - /** @var $substitutions Substitution[] An array of key/value substitutions to be be applied to the text and html content of the email body */ + /** @var $substitutions Substitution[] An array of key/value substitutions + * to be be applied to the text and html content of the email body + */ private $substitutions; /** @var $subject Subject The personalized subject of the email */ private $subject; @@ -40,6 +42,7 @@ class EmailAddress implements \JsonSerializable * be be applied to the text and html content * of the email body * @param string|null $subject The personalized subject of the email + * @throws TypeException */ public function __construct( $emailAddress = null, @@ -65,9 +68,8 @@ public function __construct( * Add the email address to a EmailAddress object * * @param string $emailAddress The email address - * * @throws TypeException - */ + */ public function setEmailAddress($emailAddress) { if (!(is_string($emailAddress) && @@ -104,9 +106,8 @@ public function getEmail() * Add a name to a EmailAddress object * * @param string $name The name of the person associated with the email - * * @throws TypeException - */ + */ public function setName($name) { if (!is_string($name)) { @@ -125,13 +126,13 @@ public function setName($name) Double quotes will be shown in some email clients, so the name should only be wrapped when necessary. */ - // Only wrapp in double quote if comma or semicolon are found + // Only wrap in double quote if comma or semicolon are found if (false !== strpos($name, ',') || false !== strpos($name, ';')) { // Unescape quotes $name = stripslashes(html_entity_decode($name, ENT_QUOTES)); // Escape only double quotes $name = str_replace('"', '\\"', $name); - // Wrapp in double quotes + // Wrap in double quotes $name = '"' . $name . '"'; } $this->name = (!empty($name)) ? $name : null; @@ -153,9 +154,8 @@ public function getName() * @param array $substitutions An array of key/value substitutions to * be be applied to the text and html content * of the email body - * * @throws TypeException - */ + */ public function setSubstitutions($substitutions) { if (!is_array($substitutions)) { @@ -177,23 +177,19 @@ public function getSubstitutions() * Add a subject to a EmailAddress object * * @param string $subject The personalized subject of the email - * * @throws TypeException - */ + */ public function setSubject($subject) { if (!is_string($subject)) { throw new TypeException('$subject must be of type string.'); } - if (!($subject instanceof Subject)) { - $this->subject = new Subject($subject); - } else { - $this->subject = $subject; - } + // Now that we know it is a string, we can safely create a new subject + $this->subject = new Subject($subject); } /** - * Retrieve a subject from a EmailAddress object + * Retrieve a subject from an EmailAddress object * * @return Subject */ @@ -203,7 +199,7 @@ public function getSubject() } /** - * Return an array representing a EmailAddress object for the Twilio SendGrid API + * Return an array representing an EmailAddress object for the Twilio SendGrid API * * @return null|array */