Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions src/CommaCredentialTail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -248,23 +248,16 @@ public function creditParts(array $givenParts): array

/**
* @param list<string> $tokens
* @return array{0: list<array{0: string, 1: TokenCredentialClass}>, 1: bool}
* @return list<array{0: string, 1: TokenCredentialClass}>
*/
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
Expand Down
5 changes: 5 additions & 0 deletions tests/CredentialCollisionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''],
];
}
Expand Down
Loading