Skip to content

Commit

Permalink
Add support for titles e.g. dr
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Feb 21, 2017
1 parent 5ab3441 commit fdda9d7
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ class EmailAddress
{
protected $_username;
protected $_domain;
protected $_title;
protected $_firstName;
protected $_middleName;
protected $_lastName;
protected $_suffix;
protected $_fullName;
protected $_lower;
protected $_base;
Expand Down Expand Up @@ -78,13 +80,26 @@ protected function _calculateName()
preg_replace('([0-9])', ' ', $this->_fullName)
);

$fcheck = preg_replace('([^a-zA-Z])', '', $first);
if(strlen($fcheck) == 1)
{
$titles = ['dr', 'prof'];
foreach($titles as $title)
{
$checkLen = strlen($title) + 1;
if(substr($this->_fullName, 0, $checkLen) == $title . $fcheck)
{
$this->_title = ucfirst($title);
$this->_fullName = substr($this->_fullName, strlen($title));
$first = '';
break;
}
}
}

if(strlen($first) > 0)
{
$this->_fullName = str_replace(
$first,
$first . ' ',
$this->_fullName
);
$this->_fullName = str_replace($first, $first . ' ', $this->_fullName);
}

if(strlen($first) > 1 && strlen($this->_fullName) > 1)
Expand Down Expand Up @@ -217,6 +232,15 @@ public function getBase()
return $this->_base;
}

/**
* @return mixed
*/
public function getTitle()
{
$this->_calculate();
return $this->_title;
}

/**
* @return mixed
*/
Expand Down

0 comments on commit fdda9d7

Please sign in to comment.