1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 16:36:47 +02:00

chore: simplify if else conditions (#3843)

* chore: simplify if else conditions

* use nullsafe

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>

---------

Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
Ngô Quốc Đạt
2023-07-27 17:31:04 +07:00
committed by GitHub
parent 76004ed844
commit 59586e63e1
5 changed files with 7 additions and 17 deletions

View File

@@ -38,11 +38,7 @@ class UnparseUserMentions
? $context->mentionsUsers->find($attributes['id'])
: User::find($attributes['id']);
if ($user) {
$attributes['displayname'] = $user->display_name;
} else {
$attributes['displayname'] = $this->translator->trans('core.lib.username.deleted_text');
}
$attributes['displayname'] = $user?->display_name ?? $this->translator->trans('core.lib.username.deleted_text');
if (strpos($attributes['displayname'], '"#') !== false) {
$attributes['displayname'] = preg_replace('/"#[a-z]{0,3}[0-9]+/', '_', $attributes['displayname']);

View File

@@ -34,11 +34,7 @@ class SaveNicknameToDatabase
// If the user sets their nickname back to the username
// set the nickname to null so that it just falls back to the username
if ($user->username === $nickname) {
$user->nickname = null;
} else {
$user->nickname = $nickname;
}
$user->nickname = $user->username === $nickname ? null : $nickname;
}
}
}