Add function for assembling display names by given name and family name

This commit is contained in:
Joshua Ramon Enslin 2021-05-04 23:57:30 +02:00
parent bde3c2cb9e
commit 6dcdb3aff6
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 38 additions and 0 deletions

View File

@ -69,6 +69,25 @@ final class NodaNameSplitter {
}
/**
* Assembles first name and given name into a common name as pronounced in the given language.
*
* @param string $givenName Given name of the actor.
* @param string $familyName Family name of the actor.
* @param string $toAdd Additional information to add to the name.
*
* @return string
*/
public function assembleNameParts(string $givenName, string $familyName, string $toAdd = ''):string {
if (in_array($this->_lang, self::LANGS_FAMILY_NAME_FIRST, true)) {
return trim($familyName) . ' ' . trim($givenName) . $toAdd;
}
return trim($givenName . ' ' . $familyName) . $toAdd;
}
/**
* Constructor.
*

View File

@ -43,4 +43,23 @@ final class NodaNameSplitterTest extends TestCase {
self::assertEquals($splitter->givenNameFamilyNameFromString('Filomeno V. Aguilar, Jr.'), ['family_name' => 'Filomeno', 'given_name' => 'V. Aguilar, Jr.']);
}
/**
* Tests the assembly of full names based on given name and family name.
*
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
* @group ValidOutput
*
* @return void
*/
public function testAssembleNameParts():void {
$splitter = new NodaNameSplitter('de');
// This applied to all languages
self::assertEquals($splitter->assembleNameParts('Friedrich', 'Wilhelm', ' (1910-1920)'), 'Friedrich Wilhelm (1910-1920)');
$splitter = new NodaNameSplitter('hu');
self::assertEquals($splitter->assembleNameParts('Friedrich', 'Wilhelm'), "Wilhelm Friedrich");
}
}