Skip to content

Commit

Permalink
fix: remove dead code when setting the subject (#757)
Browse files Browse the repository at this point in the history
After a check for type string there is no way to pass in an object of type subject
so this check is dead code and can be removed.
Also fixed some minor spelling and codestyle issues in the file
  • Loading branch information
2mt-heuser authored and childish-sambino committed Jan 8, 2020
1 parent 2de6c9c commit 494a3fc
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions lib/mail/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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) &&
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -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)) {
Expand All @@ -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
*/
Expand All @@ -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
*/
Expand Down

0 comments on commit 494a3fc

Please sign in to comment.