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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 17 deletions

View File

@ -38,11 +38,7 @@ class UnparseUserMentions
? $context->mentionsUsers->find($attributes['id']) ? $context->mentionsUsers->find($attributes['id'])
: User::find($attributes['id']); : User::find($attributes['id']);
if ($user) { $attributes['displayname'] = $user?->display_name ?? $this->translator->trans('core.lib.username.deleted_text');
$attributes['displayname'] = $user->display_name;
} else {
$attributes['displayname'] = $this->translator->trans('core.lib.username.deleted_text');
}
if (strpos($attributes['displayname'], '"#') !== false) { if (strpos($attributes['displayname'], '"#') !== false) {
$attributes['displayname'] = preg_replace('/"#[a-z]{0,3}[0-9]+/', '_', $attributes['displayname']); $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 // If the user sets their nickname back to the username
// set the nickname to null so that it just falls back to the username // set the nickname to null so that it just falls back to the username
if ($user->username === $nickname) { $user->nickname = $user->username === $nickname ? null : $nickname;
$user->nickname = null;
} else {
$user->nickname = $nickname;
}
} }
} }
} }

View File

@ -115,7 +115,7 @@ class LanguagePack implements ExtenderInterface, LifecycleInterface
/** @var ExtensionManager|null $extensions */ /** @var ExtensionManager|null $extensions */
static $extensions; static $extensions;
$extensions = $extensions ?? $container->make(ExtensionManager::class); $extensions ??= $container->make(ExtensionManager::class);
return $extensions->isEnabled($slug); return $extensions->isEnabled($slug);
} }

View File

@ -199,7 +199,7 @@ class Formatter
protected function configureDefaultsOnLinks(string $xml): string protected function configureDefaultsOnLinks(string $xml): string
{ {
return Utils::replaceAttributes($xml, 'URL', function ($attributes) { return Utils::replaceAttributes($xml, 'URL', function ($attributes) {
$attributes['rel'] = $attributes['rel'] ?? 'ugc nofollow'; $attributes['rel'] ??= 'ugc nofollow';
return $attributes; return $attributes;
}); });

View File

@ -62,11 +62,9 @@ class RouteHandlerFactory
private function resolveController(callable|string $controller): Handler private function resolveController(callable|string $controller): Handler
{ {
if (is_callable($controller)) { $controller = is_callable($controller)
$controller = $this->container->call($controller); ? $this->container->call($controller)
} else { : $this->container->make($controller);
$controller = $this->container->make($controller);
}
if (! $controller instanceof Handler) { if (! $controller instanceof Handler) {
throw new InvalidArgumentException('Controller must be an instance of '.Handler::class); throw new InvalidArgumentException('Controller must be an instance of '.Handler::class);