diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index f39f5078..ac5d9558 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -506,11 +506,18 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe */ public function getFullName(bool $including_username = false): string { + $tmp = $this->getFirstName(); + //Dont add a space, if the name has only one part (it would look strange) + if (!empty($this->getFirstName()) && !empty($this->getLastName())) { + $tmp .= ' '; + } + $tmp .= $this->getLastName(); + if ($including_username) { - return sprintf('%s %s (@%s)', $this->getFirstName(), $this->getLastName(), $this->getName()); + $tmp .= sprintf(' (@%s)', $this->getName()); } - return sprintf('%s %s', $this->getFirstName(), $this->getLastName()); + return $tmp; } /** diff --git a/tests/Entity/UserSystem/UserTest.php b/tests/Entity/UserSystem/UserTest.php index 813d5435..4ac24c80 100644 --- a/tests/Entity/UserSystem/UserTest.php +++ b/tests/Entity/UserSystem/UserTest.php @@ -58,6 +58,9 @@ class UserTest extends TestCase $this->assertSame('John Doe', $user->getFullName(false)); $this->assertSame('John Doe (@username)', $user->getFullName(true)); + + $user->setLastName(''); + $this->assertSame('John (@username)', $user->getFullName(true)); } public function googleAuthenticatorEnabledDataProvider(): array