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 df4233a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Mapper/LastnameMapper.php
Expand Up @@ -64,7 +64,9 @@ protected function mapReversedParts(array $parts): array
break;
}

$parts[$k] = new Lastname($part);
$lastname = new Lastname($part);
$lastname->setAsNotPrefix();
$parts[$k] = $lastname;
}

return $parts;
Expand Down
9 changes: 8 additions & 1 deletion src/Part/Lastname.php
Expand Up @@ -24,6 +24,8 @@ class Lastname extends AbstractPart
'la' => 'la',
'ter' => 'ter'
];
/** @var bool */
private $checkForPrefixes = true;

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

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

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

public function setAsNotPrefix()
{
$this->checkForPrefixes = false;
}
}
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 df4233a

Please sign in to comment.