From df4233a1a2f407c02a4634900cc60d116af6dfc3 Mon Sep 17 00:00:00 2001 From: Alejandro Estringana Ruiz Date: Mon, 14 Aug 2017 11:51:00 +1000 Subject: [PATCH] IOPS-1870 Allow Van as surname when only surname 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. --- src/Mapper/LastnameMapper.php | 4 +++- src/Part/Lastname.php | 9 ++++++++- tests/ParserTest.php | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Mapper/LastnameMapper.php b/src/Mapper/LastnameMapper.php index af27107..55d5e88 100644 --- a/src/Mapper/LastnameMapper.php +++ b/src/Mapper/LastnameMapper.php @@ -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; diff --git a/src/Part/Lastname.php b/src/Part/Lastname.php index 297c395..b0cab98 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 $checkForPrefixes = true; /** * check if the given word is a lastname prefix @@ -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; + } } 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', [