diff --git a/src/CommaCredentialTail.php b/src/CommaCredentialTail.php index b3bc6d1..173763f 100644 --- a/src/CommaCredentialTail.php +++ b/src/CommaCredentialTail.php @@ -75,7 +75,7 @@ public function split(array $tailSegments, bool $uniformInput): array continue; } - [$tokenClasses, $hasDictionarySuffix] = $this->classifyTokens($tokens, $uniformInput); + $tokenClasses = $this->classifyTokens($tokens, $uniformInput); $preserveSingleLetterInitial = self::containsSingleLetterRoman($tokenClasses) && $hasPreservedName; $effectiveTokenClasses = $preserveSingleLetterInitial @@ -248,23 +248,16 @@ public function creditParts(array $givenParts): array /** * @param list $tokens - * @return array{0: list, 1: bool} + * @return list */ private function classifyTokens(array $tokens, bool $uniformInput): array { $tokenClasses = []; - $hasDictionarySuffix = false; foreach ($tokens as $token) { - $class = $this->credentialClass($token, $uniformInput); - - if ($class === TokenCredentialClass::DictionaryCredential) { - $hasDictionarySuffix = true; - } - - $tokenClasses[] = [$token, $class]; + $tokenClasses[] = [$token, $this->credentialClass($token, $uniformInput)]; } - return [$tokenClasses, $hasDictionarySuffix]; + return $tokenClasses; } private function credentialClass(string $token, bool $uniformInput): TokenCredentialClass diff --git a/tests/CredentialCollisionTest.php b/tests/CredentialCollisionTest.php index f275968..6ca125d 100644 --- a/tests/CredentialCollisionTest.php +++ b/tests/CredentialCollisionTest.php @@ -371,6 +371,11 @@ public static function commaFormSingleLetterInitialProvider(): array 'isolated I after given' => ['Smith, Michelle, I', 'Michelle', 'I', ''], 'isolated V after given' => ['Smith, Michelle, V', 'Michelle', 'V', ''], 'isolated X after given' => ['Smith, Michelle, X', 'Michelle', 'X', ''], + 'initial before same-segment credential' => ['Smith, Michelle, I MD', 'Michelle', 'I', 'MD'], + 'initial after same-segment credential' => ['Smith, Michelle, MD I', 'Michelle', 'I', 'MD'], + 'initial before later credential' => ['Smith, Michelle, I, MD', 'Michelle', 'I', 'MD'], + 'initial after earlier credential' => ['Smith, Michelle, MD, I', 'Michelle', 'I', 'MD'], + 'initial alone does not anchor candidate' => ['Smith, Michelle, I, FACS', 'Michelle', 'I', ''], 'isolated lowercase i after given' => ['Smith, Michelle, i', 'Michelle', 'I', ''], ]; }