Skip to content

Commit

Permalink
chore: simplify if else conditions (#3843)
Browse files Browse the repository at this point in the history
* chore: simplify if else conditions

* use nullsafe

Co-authored-by: Sami Mazouz <[email protected]>

---------

Co-authored-by: Sami Mazouz <[email protected]>
  • Loading branch information
datlechin and SychO9 authored Jul 27, 2023
1 parent 76004ed commit 59586e6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 17 deletions.
6 changes: 1 addition & 5 deletions extensions/mentions/src/Formatter/UnparseUserMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ protected function updateUserMentionTags(mixed $context, string $xml): string
? $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']);
Expand Down
6 changes: 1 addition & 5 deletions extensions/nicknames/src/SaveNicknameToDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ public function handle(Saving $event): void

// 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;
}
}
}
2 changes: 1 addition & 1 deletion framework/core/src/Extend/LanguagePack.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function shouldLoad(SplFileInfo $file, Container $container): bool

/** @var ExtensionManager|null $extensions */
static $extensions;
$extensions = $extensions ?? $container->make(ExtensionManager::class);
$extensions ??= $container->make(ExtensionManager::class);

return $extensions->isEnabled($slug);
}
Expand Down
2 changes: 1 addition & 1 deletion framework/core/src/Formatter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function getJs(): string
protected function configureDefaultsOnLinks(string $xml): string
{
return Utils::replaceAttributes($xml, 'URL', function ($attributes) {
$attributes['rel'] = $attributes['rel'] ?? 'ugc nofollow';
$attributes['rel'] ??= 'ugc nofollow';

return $attributes;
});
Expand Down
8 changes: 3 additions & 5 deletions framework/core/src/Http/RouteHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ public function toAdmin(string $content = null): Closure

private function resolveController(callable|string $controller): Handler
{
if (is_callable($controller)) {
$controller = $this->container->call($controller);
} else {
$controller = $this->container->make($controller);
}
$controller = is_callable($controller)
? $this->container->call($controller)
: $this->container->make($controller);

if (! $controller instanceof Handler) {
throw new InvalidArgumentException('Controller must be an instance of '.Handler::class);
Expand Down

0 comments on commit 59586e6

Please sign in to comment.