Skip to content

Commit

Permalink
IOPS-1870 Allow Van as surname when only surname
Browse files Browse the repository at this point in the history
It was detected that Van was always detected as prefix of surname.
However, it did not make sense to have a prefix without a surname.
This PR fixes that, it checks if it is the only surname and if it
is, it get the only surname as surname without paying attention
to the prefixes.
  • Loading branch information
estringana committed Aug 14, 2017
1 parent d45c6ec commit 1124002
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
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
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
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
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 1124002

Please sign in to comment.