mirror of
https://github.com/flarum/framework.git
synced 2025-02-01 12:00:45 +08: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:
parent
76004ed844
commit
59586e63e1
|
@ -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']);
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
});
|
});
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user