Convert optional() to nullsafe operator

Applies patch 2/21 from pixelfed-staging PR #9: replaces optional($x)->y
with $x?->y across 16 files. Pint-clean.
pull/7058/head
Your Name 3 weeks ago
parent 802db3791d
commit 042ab0a6e4

@ -170,7 +170,7 @@ class MediaFilterCleanup extends Command
'remote_media' => (bool) $m->remote_media ? 'true' : 'false',
'mime' => $m->mime,
'size' => $m->size,
'created_at' => optional($m->created_at)->toDateTimeString(),
'created_at' => $m->created_at?->toDateTimeString(),
'media_path' => $m->media_path,
];

@ -52,7 +52,7 @@ class StatusAvatar extends Command
['cdn_url', $avatar->cdn_url ?? 'null'],
['remote_url', $avatar->remote_url ?? 'null'],
['size', $avatar->size ?? 'null'],
['last_fetched_at', optional($avatar->last_fetched_at)->toDateTimeString() ?? 'null'],
['last_fetched_at', $avatar->last_fetched_at?->toDateTimeString() ?? 'null'],
]);
if ($avatar->media_path && ! Str::startsWith($avatar->media_path, 'http')) {

@ -26,7 +26,7 @@ trait ManagesCachedPages
return [
'title' => $page->title,
'content' => $page->content,
'created_at' => optional($page->created_at)->format('M d, Y'),
'created_at' => $page->created_at?->format('M d, Y'),
];
}
}

@ -70,7 +70,7 @@ class GroupController extends GroupFederationController
{
abort_unless(config('groups.enabled'), 404);
$group = Group::find($gid);
$pid = optional($request->user())->profile_id ?? false;
$pid = $request->user()?->profile_id ?? false;
if (! $group || $group->status) {
return response()->view('groups.unavailable')->setStatusCode(404);
@ -91,7 +91,7 @@ class GroupController extends GroupFederationController
{
abort_unless(config('groups.enabled'), 404);
$group = Group::whereNull('status')->findOrFail($id);
$pid = optional($request->user())->profile_id ?? false;
$pid = $request->user()?->profile_id ?? false;
$group = $this->toJson($group, $pid);

@ -35,7 +35,7 @@ class GroupsCommentController extends Controller
'limit' => 'nullable|integer|min:3|max:10',
]);
$pid = optional($request->user())->profile_id;
$pid = $request->user()?->profile_id;
$gid = $request->input('gid');
$sid = $request->input('sid');
$cid = $request->has('cid') && $request->filled('cid') ? $request->input('cid') : false;

@ -114,7 +114,7 @@ class GroupsFeedController extends Controller
{
$group = Group::findOrFail($id);
$user = $request->user();
$pid = optional($user)->profile_id ?? false;
$pid = $user?->profile_id ?? false;
abort_if(! $group->isMember($pid), 404);
$max = $request->input('max_id');
$limit = $request->limit ?? 3;

@ -141,9 +141,9 @@ class PersonalAccessTokenController extends Controller
'name' => $token->name,
'scopes' => $token->scopes ?? [],
'revoked' => (bool) $token->revoked,
'created_at' => optional($token->created_at)->toJSON(),
'updated_at' => optional($token->updated_at)->toJSON(),
'expires_at' => optional($token->expires_at)->toJSON(),
'created_at' => $token->created_at?->toJSON(),
'updated_at' => $token->updated_at?->toJSON(),
'expires_at' => $token->expires_at?->toJSON(),
];
}

@ -76,7 +76,7 @@ class ProfileController extends Controller
$key = 'profile:settings:'.$user->id;
$ttl = now()->addHours(6);
$settings = Cache::remember($key, $ttl, function () use ($user) {
$s = optional($user->user)->settings;
$s = $user->user?->settings;
return [
'crawlable' => $s->crawlable ?? true,
@ -111,7 +111,7 @@ class ProfileController extends Controller
$key = 'profile:settings:'.$user->id;
$ttl = now()->addHours(6);
$settings = Cache::remember($key, $ttl, function () use ($user) {
$s = optional($user->user)->settings;
$s = $user->user?->settings;
return [
'crawlable' => $s->crawlable ?? true,

@ -51,8 +51,8 @@ class AdminRemoteReport extends JsonResource
'statuses' => $statuses,
'message' => $this->comment,
'report_meta' => $this->report_meta,
'created_at' => optional($this->created_at)->format('c'),
'action_taken_at' => optional($this->action_taken_at)->format('c'),
'created_at' => $this->created_at?->format('c'),
'action_taken_at' => $this->action_taken_at?->format('c'),
];
return $res;

@ -85,8 +85,8 @@ class MediaDeletePipeline implements ShouldBeUniqueUntilProcessing, ShouldQueue
'thumbnail_path' => $media->thumbnail_path,
'hls_path' => $media->hls_path,
'remote_media' => (bool) $media->remote_media,
'created_at' => optional($media->created_at)->toDateTimeString(),
'updated_at' => optional($media->updated_at)->toDateTimeString(),
'created_at' => $media->created_at?->toDateTimeString(),
'updated_at' => $media->updated_at?->toDateTimeString(),
]);
return 1;

@ -45,7 +45,7 @@ class CustomEmoji extends Model
'id' => $emoji->id,
'shortcode' => $emoji->shortcode,
'media_path' => $emoji->media_path,
'updated_at' => optional($emoji->updated_at)->toAtomString(),
'updated_at' => $emoji->updated_at?->toAtomString(),
'disabled' => $emoji->disabled,
];
});

@ -49,7 +49,7 @@ class GroupPostService
{
$gid = $request->input('gid');
$sid = $request->input('sid');
$pid = optional($request->user())->profile_id ?? false;
$pid = $request->user()?->profile_id ?? false;
$group = Group::findOrFail($gid);

@ -70,7 +70,7 @@ class AccountTransformer extends Fractal\TransformerAbstract
'is_admin' => (bool) $is_admin,
'created_at' => $profile->created_at->toJSON(),
'header_bg' => $profile->header_bg,
'last_fetched_at' => optional($profile->last_fetched_at)->toJSON(),
'last_fetched_at' => $profile->last_fetched_at?->toJSON(),
'pronouns' => PronounService::get($profile->id),
'location' => $profile->location,
];

@ -30,7 +30,7 @@ class AccountTransformer extends Fractal\TransformerAbstract
'followers_count' => (int) $profile->followerCount(),
'following_count' => (int) $profile->followingCount(),
'statuses_count' => (int) $profile->statusCount(),
'last_status_at' => optional($profile->last_status_at)->toJSON(),
'last_status_at' => $profile->last_status_at?->toJSON(),
'emojis' => [],
'moved' => null,
'fields' => [],

@ -1034,7 +1034,7 @@ class Helpers
if ($inReplyTo) {
$reply_to = self::statusFirstOrFetch($inReplyTo);
if ($reply_to) {
$reply_to = optional($reply_to)->id;
$reply_to = $reply_to?->id;
}
} else {
$reply_to = null;

@ -113,7 +113,7 @@
<td class="font-weight-bold">{{$story->type}}</td>
<td class="font-weight-bold">{{$story->view_count ?? 0}}</td>
<td class="font-weight-bold">{{$story->created_at->diffForHumans(null, true, true, true)}}</td>
<td class="font-weight-bold">{{optional($story->expires_at)->diffForHumans(null, true, true, true)}}</td>
<td class="font-weight-bold">{{$story->expires_at?->diffForHumans(null, true, true, true)}}</td>
<td class="text-right">
<div class="dropdown">
<a class="btn btn-sm btn-icon-only text-light" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

Loading…
Cancel
Save