From 0435d08568baf6c502c623e8fc8075375d6ae151 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 18 Sep 2026 12:51:48 +0930 Subject: [PATCH] RemoveAlwaysElseRector --- .gitignore | 1 + .../Commands/Admin/SendUpdateActor.php | 113 +++++---- .../Commands/Internal/PushGatewayRefresh.php | 43 ++-- app/Http/Controllers/AccountController.php | 12 +- .../Admin/AdminReportController.php | 8 +- .../Admin/AdminSettingsController.php | 21 +- app/Http/Controllers/AdminController.php | 31 +-- .../AdminCuratedRegisterController.php | 15 +- .../AdminShadowFilterController.php | 6 +- .../Controllers/Api/AdminApiController.php | 19 +- app/Http/Controllers/Api/ApiV1Controller.php | 9 +- .../Controllers/Auth/RegisterController.php | 13 +- app/Http/Controllers/FederationController.php | 21 +- .../Groups/GroupsPostController.php | 3 +- app/Http/Controllers/ImportPostController.php | 34 ++- app/Http/Controllers/ProfileController.php | 88 ++++--- app/Http/Controllers/PublicApiController.php | 110 +++++---- app/Http/Controllers/RemoteAuthController.php | 21 +- app/Http/Controllers/SiteController.php | 3 +- app/Http/Middleware/AccountInterstitial.php | 7 +- app/Jobs/InboxPipeline/DeleteWorker.php | 29 +-- app/Jobs/InboxPipeline/InboxWorker.php | 3 +- app/Services/AutospamService.php | 7 +- .../Federation/ActiveSharedInboxService.php | 22 +- app/Services/SearchApiV2Service.php | 216 +++++++++--------- app/Util/ActivityPub/Helpers.php | 3 +- app/Util/Lexer/Validator.php | 3 +- rector.php | 19 ++ 28 files changed, 417 insertions(+), 463 deletions(-) create mode 100644 rector.php diff --git a/.gitignore b/.gitignore index 6f7ac05c2..3f5dc1196 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ /storage/psalm-reports /psalm.sarif.json /.psalm-cache +.kiro/ diff --git a/app/Console/Commands/Admin/SendUpdateActor.php b/app/Console/Commands/Admin/SendUpdateActor.php index 4ea95964e..6ac28c27b 100644 --- a/app/Console/Commands/Admin/SendUpdateActor.php +++ b/app/Console/Commands/Admin/SendUpdateActor.php @@ -52,68 +52,65 @@ class SendUpdateActor extends Command ); return Command::SUCCESS; - } else { - $domain = $this->anticipate('Enter the instance domain', function ($input) { - return Instance::where('domain', 'like', '%'.$input.'%')->pluck('domain')->toArray(); - }); - if (! $this->confirm('Are you sure you want to send actor updates to '.$domain.'?')) { - return; - } - if ($cur = Instance::whereDomain($domain)->whereNotNull('actors_last_synced_at')->first()) { - if (! $this->option('force')) { - $this->error('ERROR: Cannot re-sync this instance, it was already synced on '.$cur->actors_last_synced_at); - - return; - } - } - $this->touchStorageCache($domain); - $this->line(' '); - $this->error('Keep this window open during this process or it will not complete!'); - $sharedInbox = Profile::whereDomain($domain)->whereNotNull('sharedInbox')->first(); - if (! $sharedInbox) { - $this->error('ERROR: Cannot find the sharedInbox of '.$domain); + } + $domain = $this->anticipate('Enter the instance domain', function ($input) { + return Instance::where('domain', 'like', '%'.$input.'%')->pluck('domain')->toArray(); + }); + if (! $this->confirm('Are you sure you want to send actor updates to '.$domain.'?')) { + return; + } + if ($cur = Instance::whereDomain($domain)->whereNotNull('actors_last_synced_at')->first()) { + if (! $this->option('force')) { + $this->error('ERROR: Cannot re-sync this instance, it was already synced on '.$cur->actors_last_synced_at); return; } - $url = $sharedInbox->sharedInbox; - $this->line(' '); - $this->info('Found sharedInbox: '.$url); - $bar = $this->output->createProgressBar($totalUserCount); - $bar->start(); - - $startCache = $this->getStorageCache($domain); - User::whereNull('status')->when($startCache, function ($query, $startCache) use ($bar) { - $bar->advance($startCache); - - return $query->where('id', '>', $startCache); - })->chunk(50, function ($users) use ($bar, $url, $domain) { - foreach ($users as $user) { - $this->updateStorageCache($domain, $user->id); - $profile = Profile::find($user->profile_id); - if (! $profile) { - continue; - } - $body = $this->updateObject($profile); - try { - Helpers::sendSignedObject($profile, $url, $body); - } catch (\Throwable) { - // Best-effort per user: a single bad host (transport - // failure, invalid destination, etc.) must not abort the - // fleet-wide actor update. - continue; - } - $bar->advance(); - } - }); - $bar->finish(); - $this->line(' '); - $instance = Instance::whereDomain($domain)->firstOrFail(); - $instance->actors_last_synced_at = now(); - $instance->save(); - $this->info('Finished!'); - - return Command::SUCCESS; } + $this->touchStorageCache($domain); + $this->line(' '); + $this->error('Keep this window open during this process or it will not complete!'); + $sharedInbox = Profile::whereDomain($domain)->whereNotNull('sharedInbox')->first(); + if (! $sharedInbox) { + $this->error('ERROR: Cannot find the sharedInbox of '.$domain); + + return; + } + $url = $sharedInbox->sharedInbox; + $this->line(' '); + $this->info('Found sharedInbox: '.$url); + $bar = $this->output->createProgressBar($totalUserCount); + $bar->start(); + $startCache = $this->getStorageCache($domain); + User::whereNull('status')->when($startCache, function ($query, $startCache) use ($bar) { + $bar->advance($startCache); + + return $query->where('id', '>', $startCache); + })->chunk(50, function ($users) use ($bar, $url, $domain) { + foreach ($users as $user) { + $this->updateStorageCache($domain, $user->id); + $profile = Profile::find($user->profile_id); + if (! $profile) { + continue; + } + $body = $this->updateObject($profile); + try { + Helpers::sendSignedObject($profile, $url, $body); + } catch (\Throwable) { + // Best-effort per user: a single bad host (transport + // failure, invalid destination, etc.) must not abort the + // fleet-wide actor update. + continue; + } + $bar->advance(); + } + }); + $bar->finish(); + $this->line(' '); + $instance = Instance::whereDomain($domain)->firstOrFail(); + $instance->actors_last_synced_at = now(); + $instance->save(); + $this->info('Finished!'); + return Command::SUCCESS; return Command::SUCCESS; } diff --git a/app/Console/Commands/Internal/PushGatewayRefresh.php b/app/Console/Commands/Internal/PushGatewayRefresh.php index 4c42a7a0e..a0fce3d59 100644 --- a/app/Console/Commands/Internal/PushGatewayRefresh.php +++ b/app/Console/Commands/Internal/PushGatewayRefresh.php @@ -37,36 +37,29 @@ class PushGatewayRefresh extends Command $this->info('Push Notification support is active!'); return; - } else { - $this->error('Push notification support is NOT active'); - - $action = select( - label: 'Do you want to force re-check?', - options: ['Yes', 'No'], - required: true - ); - - if ($action === 'Yes') { - $recheck = NotificationAppGatewayService::forceSupportRecheck(); - if ($recheck) { - $this->info('Success! Push Notifications are now active!'); - - return; - } else { - $this->error('Error, please ensure you have a valid API key.'); - $this->line(' '); - $this->line('For more info, visit https://docs.pixelfed.org/running-pixelfed/push-notifications.html'); - $this->line(' '); - - return; - } + } + $this->error('Push notification support is NOT active'); + $action = select( + label: 'Do you want to force re-check?', + options: ['Yes', 'No'], + required: true + ); + if ($action === 'Yes') { + $recheck = NotificationAppGatewayService::forceSupportRecheck(); + if ($recheck) { + $this->info('Success! Push Notifications are now active!'); return; - } else { - exit; } + $this->error('Error, please ensure you have a valid API key.'); + $this->line(' '); + $this->line('For more info, visit https://docs.pixelfed.org/running-pixelfed/push-notifications.html'); + $this->line(' '); + return; return; } + exit; + return; } } diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 398cd67a2..ed6ada947 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -133,9 +133,8 @@ class AccountController extends Controller if ($request->wantsJson()) { return response()->json($res); - } else { - return redirect()->back(); } + return redirect()->back(); } public function unmute(Request $request): JsonResponse|RedirectResponse @@ -185,9 +184,8 @@ class AccountController extends Controller if ($request->wantsJson()) { return response()->json($res); - } else { - return redirect()->back(); } + return redirect()->back(); } public function block(Request $request): JsonResponse|RedirectResponse @@ -271,9 +269,8 @@ class AccountController extends Controller if ($request->wantsJson()) { return response()->json($res); - } else { - return redirect()->back(); } + return redirect()->back(); } public function unblock(Request $request): JsonResponse|RedirectResponse @@ -322,9 +319,8 @@ class AccountController extends Controller if ($request->wantsJson()) { return response()->json($res); - } else { - return redirect()->back(); } + return redirect()->back(); } public function followRequests(Request $request): View diff --git a/app/Http/Controllers/Admin/AdminReportController.php b/app/Http/Controllers/Admin/AdminReportController.php index fc0a037b1..f67cc92b7 100644 --- a/app/Http/Controllers/Admin/AdminReportController.php +++ b/app/Http/Controllers/Admin/AdminReportController.php @@ -704,12 +704,14 @@ trait AdminReportController ]); $report = Report::whereObjectId($request->input('object_id'))->findOrFail($request->input('id')); - if ($request->input('action_type') === 'profile') { return $this->reportsHandleProfileAction($report, $request->input('action')); - } elseif ($request->input('action_type') === 'post') { + } + if ($request->input('action_type') === 'post') { return $this->reportsHandleStatusAction($report, $request->input('action')); - } elseif ($request->input('action_type') === 'story') { + } + + if ($request->input('action_type') === 'story') { return $this->reportsHandleStoryAction($report, $request->input('action')); } diff --git a/app/Http/Controllers/Admin/AdminSettingsController.php b/app/Http/Controllers/Admin/AdminSettingsController.php index e2b2c0122..d3b3d59b3 100644 --- a/app/Http/Controllers/Admin/AdminSettingsController.php +++ b/app/Http/Controllers/Admin/AdminSettingsController.php @@ -373,15 +373,14 @@ trait AdminSettingsController if (! $rules) { return []; - } else { - $json = json_decode($rules, true); - $idx = array_search($val, $json); - if ($idx !== false) { - unset($json[$idx]); - $json = array_values($json); - } - ConfigCacheService::put('app.rules', json_encode(array_values($json))); } + $json = json_decode($rules, true); + $idx = array_search($val, $json); + if ($idx !== false) { + unset($json[$idx]); + $json = array_values($json); + } + ConfigCacheService::put('app.rules', json_encode(array_values($json))); Cache::forget('api:v1:instance-data:rules'); Cache::forget('api:v1:instance-data-response-v1'); @@ -397,9 +396,8 @@ trait AdminSettingsController if (! $rules) { return []; - } else { - ConfigCacheService::put('app.rules', json_encode([])); } + ConfigCacheService::put('app.rules', json_encode([])); Cache::forget('api:v1:instance-data:rules'); Cache::forget('api:v1:instance-data-response-v1'); @@ -535,9 +533,8 @@ trait AdminSettingsController $cloud_ready = ! empty(config('filesystems.disks.'.$cloud_disk.'.key')) && ! empty(config('filesystems.disks.'.$cloud_disk.'.secret')); if (! $cloud_ready) { return redirect()->back()->withErrors(['cloud_storage' => 'Must configure cloud storage before enabling!']); - } else { - ConfigCacheService::put('pixelfed.cloud_storage', true); } + ConfigCacheService::put('pixelfed.cloud_storage', true); } } ConfigCacheService::put('federation.activitypub.authorized_fetch', $request->boolean('authorized_fetch')); diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 95066be4f..d2f081e0c 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -559,18 +559,22 @@ class AdminController extends Controller if ($sort == 'all') { if ($pg) { return $query->latest(); - } else { - return $query->groupBy('shortcode')->latest(); } - } elseif ($sort == 'local') { + return $query->groupBy('shortcode')->latest(); + } + if ($sort == 'local') { return $query->latest()->where('domain', '=', config('pixelfed.domain.app')); - } elseif ($sort == 'remote') { + } + if ($sort == 'remote') { return $query->latest()->where('domain', '!=', config('pixelfed.domain.app')); - } elseif ($sort == 'duplicates') { + } + if ($sort == 'duplicates') { return $query->latest()->duplicateShortcodes(); - } elseif ($sort == 'disabled') { + } + if ($sort == 'disabled') { return $query->latest()->whereDisabled(true); - } elseif ($sort == 'search') { + } + if ($sort == 'search') { $q = $query ->latest() ->where('shortcode', 'like', '%'.$request->input('q').'%') @@ -580,7 +584,6 @@ class AdminController extends Controller $q = $q->groupBy('shortcode'); } } - return $q; } }) @@ -698,15 +701,17 @@ class AdminController extends Controller ->when($filter, function ($q, $filter) { if ($filter === 'cw') { return $q->where('cw', true); - } elseif ($filter === 'unlisted') { + } + if ($filter === 'unlisted') { return $q->where('unlisted', true); - } elseif ($filter === 'banned') { + } + if ($filter === 'banned') { return $q->where('status', 'banned'); - } elseif ($filter === 'newest') { + } + if ($filter === 'newest') { return $q->orderByDesc('id'); - } else { - return $q; } + return $q; }) ->cursorPaginate(10) ->withQueryString(); diff --git a/app/Http/Controllers/AdminCuratedRegisterController.php b/app/Http/Controllers/AdminCuratedRegisterController.php index fe4a7f4d5..75a5b8823 100644 --- a/app/Http/Controllers/AdminCuratedRegisterController.php +++ b/app/Http/Controllers/AdminCuratedRegisterController.php @@ -40,22 +40,27 @@ class AdminCuratedRegisterController extends Controller }) ->whereNotNull('email_verified_at') ->whereIsClosed(false); - } elseif ($filter === 'all') { + } + if ($filter === 'all') { return $q; - } elseif ($filter === 'responses') { + } + if ($filter === 'responses') { return $q->whereIsClosed(false) ->whereNotNull('email_verified_at') ->where('user_has_responded', true) ->where('is_awaiting_more_info', true); - } elseif ($filter === 'awaiting') { + } + if ($filter === 'awaiting') { return $q->whereIsClosed(false) ->where('is_rejected', false) ->where('is_approved', false) ->where('user_has_responded', false) ->where('is_awaiting_more_info', true); - } elseif ($filter === 'approved') { + } + if ($filter === 'approved') { return $q->whereIsClosed(true)->whereIsApproved(true); - } elseif ($filter === 'rejected') { + } + if ($filter === 'rejected') { return $q->whereIsClosed(true)->whereIsRejected(true); } }) diff --git a/app/Http/Controllers/AdminShadowFilterController.php b/app/Http/Controllers/AdminShadowFilterController.php index b34e72613..c2e05e641 100644 --- a/app/Http/Controllers/AdminShadowFilterController.php +++ b/app/Http/Controllers/AdminShadowFilterController.php @@ -23,11 +23,11 @@ class AdminShadowFilterController extends Controller ->when($filter, function ($q, $filter) { if ($filter == 'all') { return $q; - } elseif ($filter == 'inactive') { + } + if ($filter == 'inactive') { return $q->whereActive(false); - } else { - return $q; } + return $q; }, function ($q, $filter) { return $q->whereActive(true); }) diff --git a/app/Http/Controllers/Api/AdminApiController.php b/app/Http/Controllers/Api/AdminApiController.php index 1314e8d43..963ad5516 100644 --- a/app/Http/Controllers/Api/AdminApiController.php +++ b/app/Http/Controllers/Api/AdminApiController.php @@ -560,24 +560,18 @@ class AdminApiController extends Controller $action = $request->input('action'); abort_if($user->is_admin == true && $action !== 'refresh_stats', 400, 'Cannot moderate admin accounts'); - if ($action === 'delete') { if (config('pixelfed.account_deletion') == false) { abort(404); } - abort_if($user->is_admin, 400, 'Cannot delete an admin account.'); - $ts = now()->addMonth(); - $user->status = 'delete'; $user->delete_after = $ts; $user->save(); - $profile->status = 'delete'; $profile->delete_after = $ts; $profile->save(); - ModLogService::boot() ->objectUid($profile->id) ->objectId($profile->id) @@ -586,10 +580,8 @@ class AdminApiController extends Controller ->action('admin.user.delete') ->accessLevel('admin') ->save(); - PublicTimelineService::deleteByProfileId($profile->id); NetworkTimelineService::deleteByProfileId($profile->id); - if ($profile->user_id) { DB::table('oauth_access_tokens')->whereUserId($user->id)->delete(); DB::table('oauth_auth_codes')->whereUserId($user->id)->delete(); @@ -609,12 +601,13 @@ class AdminApiController extends Controller AccountService::del($profile->id); DeleteRemoteProfilePipeline::dispatch($profile)->onQueue('high'); } - return [ 'status' => 200, 'msg' => 'deleted', ]; - } elseif ($action === 'refresh_stats') { + } + + if ($action === 'refresh_stats') { $profile->following_count = DB::table('followers')->whereProfileId($user->profile_id)->count(); $profile->followers_count = DB::table('followers')->whereFollowingId($user->profile_id)->count(); $statusCount = Status::whereProfileId($user->profile_id) @@ -685,7 +678,8 @@ class AdminApiController extends Controller ->save(); $profile->no_autolink = ! $profile->no_autolink; $profile->save(); - } else { + } + else { $profile->{$action} = filter_var($request->input('value'), FILTER_VALIDATE_BOOLEAN); $profile->save(); @@ -741,9 +735,8 @@ class AdminApiController extends Controller ->when($filter, function ($query, $filter) { if ($filter === 'all') { return $query; - } else { - return $query->where($filter, true); } + return $query->where($filter, true); }) ->when($sortBy, function ($query, $sortBy) use ($sort) { return $query->orderBy($sortBy, $sort); diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 6de8ac81d..2bf48b40a 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1579,9 +1579,8 @@ class ApiV1Controller extends Controller } return $this->json($res, 200, ['Link' => $link]); - } else { - return $this->json($res); } + return $this->json($res); } /** @@ -2737,12 +2736,10 @@ class ApiV1Controller extends Controller Cache::set('pf:services:apiv1:home:cached:coldbootcheck:'.$pid, 1, 86400); FeedWarmCachePipeline::dispatchSync($pid); - return response()->json([], 206); - } else { - Cache::set('pf:services:apiv1:home:cached:coldbootcheck:'.$pid, 1, 86400); - return response()->json([], 206); } + Cache::set('pf:services:apiv1:home:cached:coldbootcheck:'.$pid, 1, 86400); + return response()->json([], 206); } $res = collect($res) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 2987528b7..9bc5f7c0e 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -155,16 +155,13 @@ class RegisterController extends Controller } return view('auth.register'); - } else { - return view('auth.register'); - } - } else { - if ((bool) config_cache('instance.curated_registration.enabled') && config('instance.curated_registration.state.fallback_on_closed_reg')) { - return redirect('/auth/sign_up'); - } else { - abort(404); } + return view('auth.register'); + } + if ((bool) config_cache('instance.curated_registration.enabled') && config('instance.curated_registration.state.fallback_on_closed_reg')) { + return redirect('/auth/sign_up'); } + abort(404); } /** diff --git a/app/Http/Controllers/FederationController.php b/app/Http/Controllers/FederationController.php index 3e9d11619..beb9e7e92 100644 --- a/app/Http/Controllers/FederationController.php +++ b/app/Http/Controllers/FederationController.php @@ -104,9 +104,8 @@ class FederationController extends Controller return response()->json($webfinger, 200, [], JSON_UNESCAPED_SLASHES) ->header('Access-Control-Allow-Origin', '*'); - } else { - return response('', 400); } + return response('', 400); } $hash = hash('sha256', $resource); $key = 'federation:webfinger:sha256:'.$hash; @@ -182,7 +181,6 @@ class FederationController extends Controller if (in_array($domain, InstanceService::getBannedDomains())) { return; } - if (isset($obj['type']) && $obj['type'] === 'Delete') { if (isset($obj['object']) && isset($obj['object']['type']) && isset($obj['object']['id'])) { if ($obj['object']['type'] === 'Person') { @@ -207,11 +205,13 @@ class FederationController extends Controller return; } } - return; - } elseif (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) { + } + + if (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) { dispatch(new InboxValidator($username, $headers, $payload))->onQueue('follow'); - } else { + } + else { dispatch(new InboxValidator($username, $headers, $payload))->onQueue('high'); } } @@ -237,7 +237,6 @@ class FederationController extends Controller if (in_array($domain, InstanceService::getBannedDomains())) { return; } - if (isset($obj['type']) && $obj['type'] === 'Delete') { if (isset($obj['object']) && isset($obj['object']['type']) && isset($obj['object']['id'])) { if ($obj['object']['type'] === 'Person') { @@ -262,11 +261,13 @@ class FederationController extends Controller return; } } - return; - } elseif (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) { + } + + if (isset($obj['type']) && in_array($obj['type'], ['Follow', 'Accept'])) { dispatch(new InboxWorker($headers, $payload))->onQueue('follow'); - } else { + } + else { dispatch(new InboxWorker($headers, $payload))->onQueue('shared'); } } diff --git a/app/Http/Controllers/Groups/GroupsPostController.php b/app/Http/Controllers/Groups/GroupsPostController.php index 653c36b94..81a001947 100644 --- a/app/Http/Controllers/Groups/GroupsPostController.php +++ b/app/Http/Controllers/Groups/GroupsPostController.php @@ -253,9 +253,8 @@ class GroupsPostController extends Controller if ($request->wantsJson()) { return response()->json(['Status successfully deleted.']); - } else { - return redirect($user->url()); } + return redirect($user->url()); } public function likePost(Request $request): array diff --git a/app/Http/Controllers/ImportPostController.php b/app/Http/Controllers/ImportPostController.php index 4c16b403a..8dd4d113a 100644 --- a/app/Http/Controllers/ImportPostController.php +++ b/app/Http/Controllers/ImportPostController.php @@ -275,27 +275,22 @@ class ImportPostController extends Controller if ($exts->contains('mp4')) { if ($exts->contains('jpg', 'png', 'webp')) { return 'photo:video:album'; - } else { - return 'video:album'; } - } else { - return 'photo:album'; - } - } else { - if ($exts->isEmpty()) { - return 'photo'; - } - - $ext = $exts[0]; - - if (in_array($ext, ['jpg', 'jpeg', 'png', 'webp'])) { - return 'photo'; - } elseif (in_array($ext, ['mp4'])) { - return 'video'; - } else { - return 'photo'; + return 'video:album'; } + return 'photo:album'; } + if ($exts->isEmpty()) { + return 'photo'; + } + $ext = $exts[0]; + if (in_array($ext, ['jpg', 'jpeg', 'png', 'webp'])) { + return 'photo'; + } + if (in_array($ext, ['mp4'])) { + return 'video'; + } + return 'photo'; } private function sanitizeFilename($filename): string @@ -320,9 +315,8 @@ class ImportPostController extends Controller if ($user->is_admin) { if (! $abortOnFail) { return true; - } else { - return true; } + return true; } $admin = User::whereIsAdmin(true)->first(); diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 230c1f8e2..6ba13b1c0 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -107,50 +107,43 @@ class ProfileController extends Controller } return view('profile.show', ['profile' => $profile, 'settings' => $settings]); - } else { - $key = 'profile:settings:'.$user->id; - $ttl = now()->addHours(6); - $settings = Cache::remember($key, $ttl, function () use ($user) { - $s = $user->user?->settings; - - return [ - 'crawlable' => $s->crawlable ?? true, - 'following' => [ - 'count' => $s->show_profile_following_count ?? true, - 'list' => $s->show_profile_following ?? false, - ], - 'followers' => [ - 'count' => $s->show_profile_follower_count ?? true, - 'list' => $s->show_profile_followers ?? false, - ], - ]; - }); - - if ($user->is_private == true) { - $isPrivate = $this->privateProfileCheck($user, $loggedIn); - } - - $isBlocked = $this->blockedProfileCheck($user); - - $owner = $loggedIn && Auth::id() === $user->user_id; - $is_following = ($owner === false && $request->user() !== null) ? $user->followedBy($request->user()->profile) : false; - - if ($isPrivate === true || $isBlocked === true) { - $requested = $request->user() !== null ? FollowRequest::whereFollowerId($request->user()->profile_id) - ->whereFollowingId($user->id) - ->exists() : false; - - return view('profile.private', ['user' => $user, 'is_following' => $is_following, 'requested' => $requested]); - } - - $is_admin = is_null($user->domain) ? $user->user->is_admin : false; - $profile = $user; - if ($carousel) { - return view('profile.show_carousel', ['profile' => $profile, 'settings' => $settings]); - } - - return view('profile.show', ['profile' => $profile, 'settings' => $settings]); } + $key = 'profile:settings:'.$user->id; + $ttl = now()->addHours(6); + $settings = Cache::remember($key, $ttl, function () use ($user) { + $s = $user->user?->settings; + + return [ + 'crawlable' => $s->crawlable ?? true, + 'following' => [ + 'count' => $s->show_profile_following_count ?? true, + 'list' => $s->show_profile_following ?? false, + ], + 'followers' => [ + 'count' => $s->show_profile_follower_count ?? true, + 'list' => $s->show_profile_followers ?? false, + ], + ]; + }); + if ($user->is_private == true) { + $isPrivate = $this->privateProfileCheck($user, $loggedIn); + } + $isBlocked = $this->blockedProfileCheck($user); + $owner = $loggedIn && Auth::id() === $user->user_id; + $is_following = ($owner === false && $request->user() !== null) ? $user->followedBy($request->user()->profile) : false; + if ($isPrivate === true || $isBlocked === true) { + $requested = $request->user() !== null ? FollowRequest::whereFollowerId($request->user()->profile_id) + ->whereFollowingId($user->id) + ->exists() : false; + + return view('profile.private', ['user' => $user, 'is_following' => $is_following, 'requested' => $requested]); + } + $is_admin = is_null($user->domain) ? $user->user->is_admin : false; + $profile = $user; + if ($carousel) { + return view('profile.show_carousel', ['profile' => $profile, 'settings' => $settings]); + } + return view('profile.show', ['profile' => $profile, 'settings' => $settings]); } protected function getCachedUser($username, $withTrashed = false) @@ -166,12 +159,11 @@ class ProfileController extends Controller return Profile::whereNull(['domain', 'status']) ->whereUsername($username) ->first(); - } else { - return Profile::withTrashed() - ->whereNull(['domain', 'status']) - ->whereUsername($username) - ->first(); } + return Profile::withTrashed() + ->whereNull(['domain', 'status']) + ->whereUsername($username) + ->first(); }); } diff --git a/app/Http/Controllers/PublicApiController.php b/app/Http/Controllers/PublicApiController.php index c6e283699..58cab611c 100644 --- a/app/Http/Controllers/PublicApiController.php +++ b/app/Http/Controllers/PublicApiController.php @@ -44,9 +44,8 @@ class PublicApiController extends Controller { if (! $user) { return []; - } else { - return AccountService::get($user->profile_id); } + return AccountService::get($user->profile_id); } public function getStatus(Request $request, $id) @@ -482,56 +481,55 @@ class PublicApiController extends Controller }) ->values() ->toArray(); - } else { - return Status::select( - 'id', - 'uri', - 'caption', - 'profile_id', - 'type', - 'in_reply_to_id', - 'reblog_of_id', - 'is_nsfw', - 'scope', - 'local', - 'reply_count', - 'comments_disabled', - 'place_id', - 'likes_count', - 'reblogs_count', - 'created_at', - 'updated_at' - ) - ->whereIn('type', $types) - ->when(! $textOnlyReplies, function ($q, $textOnlyReplies) { - return $q->whereNull('in_reply_to_id'); - }) - ->whereIn('profile_id', $following) - ->whereIn('visibility', ['public', 'unlisted', 'private']) - ->orderBy('created_at', 'desc') - ->limit($limit) - ->get() - ->map(function ($s) use ($user) { - try { - $status = StatusService::get($s->id, false); - if (! $status) { - return false; - } - } catch (\Exception) { + } + return Status::select( + 'id', + 'uri', + 'caption', + 'profile_id', + 'type', + 'in_reply_to_id', + 'reblog_of_id', + 'is_nsfw', + 'scope', + 'local', + 'reply_count', + 'comments_disabled', + 'place_id', + 'likes_count', + 'reblogs_count', + 'created_at', + 'updated_at' + ) + ->whereIn('type', $types) + ->when(! $textOnlyReplies, function ($q, $textOnlyReplies) { + return $q->whereNull('in_reply_to_id'); + }) + ->whereIn('profile_id', $following) + ->whereIn('visibility', ['public', 'unlisted', 'private']) + ->orderBy('created_at', 'desc') + ->limit($limit) + ->get() + ->map(function ($s) use ($user) { + try { + $status = StatusService::get($s->id, false); + if (! $status) { return false; } - $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); - $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id); - $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id); + } catch (\Exception) { + return false; + } + $status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id); + $status['bookmarked'] = (bool) BookmarkService::get($user->profile_id, $s->id); + $status['reblogged'] = (bool) ReblogService::get($user->profile_id, $s->id); - return $status; - }) - ->filter(function ($s) use ($filtered) { - return $s && isset($s['account']) && in_array($s['account']['id'], $filtered) === false; - }) - ->values() - ->toArray(); - } + return $status; + }) + ->filter(function ($s) use ($filtered) { + return $s && isset($s['account']) && in_array($s['account']['id'], $filtered) === false; + }) + ->values() + ->toArray(); } public function networkTimelineApi(Request $request): JsonResponse|Response @@ -853,16 +851,14 @@ class PublicApiController extends Controller $isFollowing = FollowerService::follows($pid, $profile['id']); return $isFollowing ? ['public', 'unlisted', 'private'] : ['public']; - } else { - if ($user) { - $pid = $user->profile_id; - $isFollowing = FollowerService::follows($pid, $profile['id']); + } + if ($user) { + $pid = $user->profile_id; + $isFollowing = FollowerService::follows($pid, $profile['id']); - return $isFollowing ? ['public', 'unlisted', 'private'] : ['public', 'unlisted']; - } else { - return ['public', 'unlisted']; - } + return $isFollowing ? ['public', 'unlisted', 'private'] : ['public', 'unlisted']; } + return ['public', 'unlisted']; } private function processStatuses($statuses, $user, $onlyMedia) diff --git a/app/Http/Controllers/RemoteAuthController.php b/app/Http/Controllers/RemoteAuthController.php index ec7c910a5..e2fa9f4d8 100644 --- a/app/Http/Controllers/RemoteAuthController.php +++ b/app/Http/Controllers/RemoteAuthController.php @@ -555,20 +555,17 @@ class RemoteAuthController extends Controller $user = User::where('username', $username)->first(); if ($user) { return ['id' => (string) $user->profile_id]; - } else { - return []; } - } else { - try { - $profile = Helpers::profileFetch($account); - if ($profile) { - return ['id' => (string) $profile->id]; - } else { - return []; - } - } catch (RequestException|\Exception) { - return []; + return []; + } + try { + $profile = Helpers::profileFetch($account); + if ($profile) { + return ['id' => (string) $profile->id]; } + return []; + } catch (RequestException|\Exception) { + return []; } } diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php index 777e4ea2d..c9e72edd4 100644 --- a/app/Http/Controllers/SiteController.php +++ b/app/Http/Controllers/SiteController.php @@ -24,9 +24,8 @@ class SiteController extends Controller { if ($request->user() !== null) { return $this->homeTimeline($request); - } else { - return $this->homeGuest(); } + return $this->homeGuest(); } public function homeGuest(): View diff --git a/app/Http/Middleware/AccountInterstitial.php b/app/Http/Middleware/AccountInterstitial.php index 550d7ba4f..b7e13dbcd 100644 --- a/app/Http/Middleware/AccountInterstitial.php +++ b/app/Http/Middleware/AccountInterstitial.php @@ -34,14 +34,11 @@ class AccountInterstitial $res = ['_refresh' => true, 'error' => 403, 'message' => \App\Models\AccountInterstitial::JSON_MESSAGE]; return response()->json($res, 403); - } else { - return redirect('/i/warning'); } - } else { - return $next($request); + return redirect('/i/warning'); } - } else { return $next($request); } + return $next($request); } } diff --git a/app/Jobs/InboxPipeline/DeleteWorker.php b/app/Jobs/InboxPipeline/DeleteWorker.php index 830eb1254..84cf88058 100644 --- a/app/Jobs/InboxPipeline/DeleteWorker.php +++ b/app/Jobs/InboxPipeline/DeleteWorker.php @@ -99,31 +99,25 @@ class DeleteWorker implements ShouldQueue DeleteRemoteProfilePipeline::dispatch($profile)->onQueue('inbox'); } - return 1; - } else { - // Signature verification failed, exit. return 1; } - } else { - // Remote user doesn't exist, exit early. + // Signature verification failed, exit. return 1; } - + // Remote user doesn't exist, exit early. return 1; - } else { - return 1; - } - } else { - $profile = null; - - if ($this->verifySignature($headers, $payload) == true) { - ActivityHandler::dispatch($headers, $profile, $payload)->onQueue('delete'); - return 1; - } else { return 1; } + return 1; + } + $profile = null; + if ($this->verifySignature($headers, $payload) == true) { + ActivityHandler::dispatch($headers, $profile, $payload)->onQueue('delete'); + + return 1; } + return 1; } @@ -200,8 +194,7 @@ class DeleteWorker implements ShouldQueue [$verified, $headers] = HttpSignature::verify($pkey, $signatureData, $headers, $inboxPath, $body); if ($verified == 1) { return true; - } else { - return false; } + return false; } } diff --git a/app/Jobs/InboxPipeline/InboxWorker.php b/app/Jobs/InboxPipeline/InboxWorker.php index 87f0f8636..7444b252e 100644 --- a/app/Jobs/InboxPipeline/InboxWorker.php +++ b/app/Jobs/InboxPipeline/InboxWorker.php @@ -159,9 +159,8 @@ class InboxWorker implements ShouldQueue [$verified, $headers] = HttpSignature::verify($pkey, $signatureData, $headers, $inboxPath, $body); if ($verified == 1) { return true; - } else { - return false; } + return false; } /** diff --git a/app/Services/AutospamService.php b/app/Services/AutospamService.php index e841888d0..51b3ff199 100644 --- a/app/Services/AutospamService.php +++ b/app/Services/AutospamService.php @@ -50,10 +50,9 @@ class AutospamService if (! Storage::exists(self::MODEL_FILE_PATH)) { return false; - } else { - if (Storage::size(self::MODEL_FILE_PATH) < 1000) { - return false; - } + } + if (Storage::size(self::MODEL_FILE_PATH) < 1000) { + return false; } return true; diff --git a/app/Services/Federation/ActiveSharedInboxService.php b/app/Services/Federation/ActiveSharedInboxService.php index 1f6619d45..ce2544a64 100644 --- a/app/Services/Federation/ActiveSharedInboxService.php +++ b/app/Services/Federation/ActiveSharedInboxService.php @@ -139,22 +139,18 @@ class ActiveSharedInboxService $res = Storage::get(self::CACHE_FILE_NAME); if (! $res) { return false; - } else { - $res = json_decode($res, true); - if (! $res || isset($res['version'], $res['data'], $res['created'], $res['updated'])) { - if (now()->parse($res['updated'])->lt(now()->subMonths(6))) { - return false; - } else { - if ($res['version'] === self::CACHE_FILE_VERSION) { - return $res; - } else { - return false; - } - } - } else { + } + $res = json_decode($res, true); + if (! $res || isset($res['version'], $res['data'], $res['created'], $res['updated'])) { + if (now()->parse($res['updated'])->lt(now()->subMonths(6))) { return false; } + if ($res['version'] === self::CACHE_FILE_VERSION) { + return $res; + } + return false; } + return false; } return false; diff --git a/app/Services/SearchApiV2Service.php b/app/Services/SearchApiV2Service.php index 3f779d1ea..d9b47f012 100644 --- a/app/Services/SearchApiV2Service.php +++ b/app/Services/SearchApiV2Service.php @@ -230,146 +230,138 @@ class SearchApiV2Service if (Helpers::validateLocalUrl($query)) { if (Str::contains($query, '/p/') || Str::contains($query, 'i/web/post/')) { return $this->resolveLocalStatus(); - } elseif (Str::contains($query, 'i/web/profile/')) { + } + if (Str::contains($query, 'i/web/profile/')) { return $this->resolveLocalProfileId(); - } else { - return $this->resolveLocalProfile(); } - } else { - if (! Helpers::validateUrl($query) && !str_contains($query, '@')) { + return $this->resolveLocalProfile(); + } + if (! Helpers::validateUrl($query) && !str_contains($query, '@')) { + return $default; + } + if ( + ! Str::startsWith($query, 'http') && + Str::substrCount($query, '@') == 1 && + str_contains($query, '@') && + !str_starts_with($query, '@') + ) { + try { + $res = WebfingerService::lookup('@'.$query, $mastodonMode); + } catch (\Exception) { return $default; } - - if ( - ! Str::startsWith($query, 'http') && - Str::substrCount($query, '@') == 1 && - str_contains($query, '@') && - !str_starts_with($query, '@') - ) { - try { - $res = WebfingerService::lookup('@'.$query, $mastodonMode); - } catch (\Exception) { + if ($res && isset($res['id'], $res['url'])) { + $domain = strtolower(parse_url($res['url'], PHP_URL_HOST)); + if (in_array($domain, $banned)) { return $default; } - if ($res && isset($res['id'], $res['url'])) { - $domain = strtolower(parse_url($res['url'], PHP_URL_HOST)); - if (in_array($domain, $banned)) { - return $default; - } - $paginated = collect($res)->take($limit)->skip($offset)->toArray(); - if (! empty($paginated)) { - $default['accounts'][] = $paginated; - } else { - $default['accounts'] = []; - } - - return $default; + $paginated = collect($res)->take($limit)->skip($offset)->toArray(); + if (! empty($paginated)) { + $default['accounts'][] = $paginated; } else { - return $default; + $default['accounts'] = []; } - } - if (Str::substrCount($query, '@') == 2) { - try { - $res = WebfingerService::lookup($query, $mastodonMode); - } catch (\Exception) { + return $default; + } + return $default; + } + if (Str::substrCount($query, '@') == 2) { + try { + $res = WebfingerService::lookup($query, $mastodonMode); + } catch (\Exception) { + return $default; + } + if ($res && isset($res['id'])) { + $domain = strtolower(parse_url($res['url'], PHP_URL_HOST)); + if (in_array($domain, $banned)) { return $default; } - if ($res && isset($res['id'])) { - $domain = strtolower(parse_url($res['url'], PHP_URL_HOST)); - if (in_array($domain, $banned)) { - return $default; - } - $paginated = collect($res)->take($limit)->skip($offset)->toArray(); - if (! empty($paginated)) { - $default['accounts'][] = $paginated; - } else { - $default['accounts'] = []; - } - - return $default; + $paginated = collect($res)->take($limit)->skip($offset)->toArray(); + if (! empty($paginated)) { + $default['accounts'][] = $paginated; } else { - return $default; + $default['accounts'] = []; } + + return $default; } + return $default; + } + if ($sid = Status::whereUri($query)->first()) { + $s = StatusService::get($sid->id, false); + if (! $s || isset($s['account']['moved'], $s['account']['moved']['id'])) { + return $default; + } + if (in_array($s['visibility'], ['public', 'unlisted'])) { + $default['statuses'][] = $s; - if ($sid = Status::whereUri($query)->first()) { - $s = StatusService::get($sid->id, false); - if (! $s || isset($s['account']['moved'], $s['account']['moved']['id'])) { - return $default; - } - if (in_array($s['visibility'], ['public', 'unlisted'])) { - $default['statuses'][] = $s; + return $default; + } + } + try { + $res = ActivityPubFetchService::get($query); - return $default; + if ($res) { + $json = json_decode($res, true); + + if (! $json || ! isset($json['@context']) || ! isset($json['type']) || ! in_array($json['type'], ['Note', 'Person'])) { + return [ + 'accounts' => [], + 'hashtags' => [], + 'statuses' => [], + ]; } - } - try { - $res = ActivityPubFetchService::get($query); + switch ($json['type']) { + case 'Note': + $obj = Helpers::statusFetch($query); + if (! $obj || ! isset($obj['id'])) { + return $default; + } + $note = $mastodonMode ? + StatusService::getMastodon($obj['id'], false) : + StatusService::get($obj['id'], false); + if (! $note) { + return $default; + } + if (! isset($note['visibility']) || ! in_array($note['visibility'], ['public', 'unlisted'])) { + return $default; + } + $default['statuses'][] = $note; + + return $default; + + case 'Person': + $obj = Helpers::profileFetch($query); + if (! $obj) { + return $default; + } + if (in_array($obj['domain'], $banned)) { + return $default; + } + $default['accounts'][] = $mastodonMode ? + AccountService::getMastodon($obj['id'], true) : + AccountService::get($obj['id'], true); - if ($res) { - $json = json_decode($res, true); + return $default; - if (! $json || ! isset($json['@context']) || ! isset($json['type']) || ! in_array($json['type'], ['Note', 'Person'])) { + default: return [ 'accounts' => [], 'hashtags' => [], 'statuses' => [], ]; - } - - switch ($json['type']) { - case 'Note': - $obj = Helpers::statusFetch($query); - if (! $obj || ! isset($obj['id'])) { - return $default; - } - $note = $mastodonMode ? - StatusService::getMastodon($obj['id'], false) : - StatusService::get($obj['id'], false); - if (! $note) { - return $default; - } - if (! isset($note['visibility']) || ! in_array($note['visibility'], ['public', 'unlisted'])) { - return $default; - } - $default['statuses'][] = $note; - - return $default; - - case 'Person': - $obj = Helpers::profileFetch($query); - if (! $obj) { - return $default; - } - if (in_array($obj['domain'], $banned)) { - return $default; - } - $default['accounts'][] = $mastodonMode ? - AccountService::getMastodon($obj['id'], true) : - AccountService::get($obj['id'], true); - - return $default; - - default: - return [ - 'accounts' => [], - 'hashtags' => [], - 'statuses' => [], - ]; - } } - } catch (\Exception) { - return [ - 'accounts' => [], - 'hashtags' => [], - 'statuses' => [], - ]; } - - return $default; + } catch (\Exception) { + return [ + 'accounts' => [], + 'hashtags' => [], + 'statuses' => [], + ]; } + return $default; } /** diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index a39c8c3dc..d5a7dcca6 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -540,9 +540,8 @@ class Helpers $res = json_decode($res, true, 8); if (json_last_error() === JSON_ERROR_NONE) { return $res; - } else { - return false; } + return false; }); } diff --git a/app/Util/Lexer/Validator.php b/app/Util/Lexer/Validator.php index 01b132a58..1562eaa94 100755 --- a/app/Util/Lexer/Validator.php +++ b/app/Util/Lexer/Validator.php @@ -384,8 +384,7 @@ class Validator extends Regex $found = preg_match($pattern, $string, $matches); if (! $optional) { return ($string || $string === '') && $found && $matches[0] === $string; - } else { - return ! (($string || $string === '') && (! $found || $matches[0] !== $string)); } + return ! (($string || $string === '') && (! $found || $matches[0] !== $string)); } } diff --git a/rector.php b/rector.php new file mode 100644 index 000000000..9606d0a14 --- /dev/null +++ b/rector.php @@ -0,0 +1,19 @@ +withPaths([ + __DIR__.'/app', + ]) + ->withSkip([ + __DIR__.'/bootstrap/cache', + __DIR__.'/storage', + __DIR__.'/vendor', + ]) + ->withRules([ + RemoveAlwaysElseRector::class, + ]);