diff --git a/src/NodaNameSplitter.php b/src/NodaNameSplitter.php index 5e1c832..427b998 100644 --- a/src/NodaNameSplitter.php +++ b/src/NodaNameSplitter.php @@ -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. * diff --git a/tests/NodaNameSplitterTest.php b/tests/NodaNameSplitterTest.php index df31170..7e2008b 100644 --- a/tests/NodaNameSplitterTest.php +++ b/tests/NodaNameSplitterTest.php @@ -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 + * @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"); + + } }