diff --git a/src/Mapper/LastnameMapper.php b/src/Mapper/LastnameMapper.php index af27107..6ee2f0f 100644 --- a/src/Mapper/LastnameMapper.php +++ b/src/Mapper/LastnameMapper.php @@ -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; diff --git a/src/Part/Lastname.php b/src/Part/Lastname.php index 297c395..9008c7d 100644 --- a/src/Part/Lastname.php +++ b/src/Part/Lastname.php @@ -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 @@ -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; + } } diff --git a/tests/Mapper/LastnameMapperTest.php b/tests/Mapper/LastnameMapperTest.php index 182b901..6aa26fe 100644 --- a/tests/Mapper/LastnameMapperTest.php +++ b/tests/Mapper/LastnameMapperTest.php @@ -13,6 +13,9 @@ class LastnameMapperTest extends AbstractMapperTest */ public function provider() { + $vanPrefix = new Lastname('van'); + $vanPrefix->setApplyPrefix(true); + return [ [ 'input' => [ @@ -58,7 +61,7 @@ public function provider() 'expectation' => [ new Salutation('Mr'), 'Lars', - new Lastname('van'), + $vanPrefix, new Lastname('Trier'), ], ], diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 238bc27..128c8b4 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -319,6 +319,13 @@ public function provider() 'lastname' => 'Truong', ], ], + [ + 'John Van', + [ + 'firstname' => 'John', + 'lastname' => 'Van', + ], + ], [ 'Mr. Van Truong', [