mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Don't add strange looking space in full name if a user does not have an first or last name.
This commit is contained in:
parent
0b16fd7697
commit
919e40e1a8
2 changed files with 12 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue