Skip to content

Commit

Permalink
Merge pull request #1 from theiconic/hotfix/OPS-1870-Allow-Van-as-Sur…
Browse files Browse the repository at this point in the history
…name

IOPS-1870 Allow Van as surname when only surname
  • Loading branch information
estringana authored Aug 14, 2017
2 parents d45c6ec + 1124002 commit ffb66dd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Mapper/LastnameMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ protected function mapReversedParts(array $parts): array

if ($this->isFollowedByLastnamePart($originalParts, $originalIndex)) {
if ($this->isApplicablePrefix($originalParts, $originalIndex)) {
$parts[$k] = new Lastname($part);
$lastname = new Lastname($part);
$lastname->setApplyPrefix(true);
$parts[$k] = $lastname;
continue;
}
break;
Expand Down
12 changes: 11 additions & 1 deletion src/Part/Lastname.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Lastname extends AbstractPart
'la' => 'la',
'ter' => 'ter'
];
/** @var bool */
private $applyPrefix = false;

/**
* check if the given word is a lastname prefix
Expand Down Expand Up @@ -57,10 +59,18 @@ public function normalize()
{
$value = $this->getValue();

if (self::isPrefix($value)) {
if ($this->applyPrefix && self::isPrefix($value)) {
return static::$prefixes[self::getKey($value)];
}

return $this->camelcase($this->getValue());
}

/**
* @param bool $applyPrefix
*/
public function setApplyPrefix(bool $applyPrefix)
{
$this->applyPrefix = $applyPrefix;
}
}
5 changes: 4 additions & 1 deletion tests/Mapper/LastnameMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class LastnameMapperTest extends AbstractMapperTest
*/
public function provider()
{
$vanPrefix = new Lastname('van');
$vanPrefix->setApplyPrefix(true);

return [
[
'input' => [
Expand Down Expand Up @@ -58,7 +61,7 @@ public function provider()
'expectation' => [
new Salutation('Mr'),
'Lars',
new Lastname('van'),
$vanPrefix,
new Lastname('Trier'),
],
],
Expand Down
7 changes: 7 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ public function provider()
'lastname' => 'Truong',
],
],
[
'John Van',
[
'firstname' => 'John',
'lastname' => 'Van',
],
],
[
'Mr. Van Truong',
[
Expand Down

0 comments on commit ffb66dd

Please sign in to comment.