From ea2a12be15f77ee397dbfe2a32bf55190f03bf6e Mon Sep 17 00:00:00 2001 From: HDVinnie Date: Tue, 14 Apr 2020 20:38:48 -0400 Subject: [PATCH] refactor: closure to arrow function --- app/Console/Commands/AutoBan.php | 4 +- .../Commands/AutoDisableInactiveUsers.php | 4 +- .../Commands/AutoRevokePermissions.php | 20 +-- .../Commands/AutoSoftDeleteDisabledUsers.php | 8 +- app/Helpers/BBCodeConverter.php | 60 ++------ app/Http/Controllers/AnnounceController.php | 12 +- .../Controllers/Auth/ActivationController.php | 8 +- .../Auth/ApplicationController.php | 8 +- app/Http/Controllers/Auth/LoginController.php | 16 +- .../Controllers/Auth/RegisterController.php | 4 +- .../Auth/ResetPasswordController.php | 8 +- app/Http/Controllers/HomeController.php | 138 +++++++----------- app/Http/Controllers/RssController.php | 8 +- app/Http/Controllers/Staff/BanController.php | 4 +- app/Http/Controllers/Staff/HomeController.php | 8 +- .../Staff/MassActionController.php | 8 +- app/Http/Controllers/Staff/PollController.php | 20 +-- app/Http/Controllers/StatsController.php | 124 ++++------------ app/Http/Middleware/CheckIfBanned.php | 4 +- app/Http/Middleware/Http2ServerPush.php | 12 +- app/Providers/AppServiceProvider.php | 8 +- app/Services/Clients/Client.php | 4 +- app/Services/Clients/TmdbClient.php | 8 +- 23 files changed, 145 insertions(+), 353 deletions(-) diff --git a/app/Console/Commands/AutoBan.php b/app/Console/Commands/AutoBan.php index cea3d924f..0ac8584f8 100644 --- a/app/Console/Commands/AutoBan.php +++ b/app/Console/Commands/AutoBan.php @@ -46,9 +46,7 @@ class AutoBan extends Command */ public function handle() { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); $bans = Warning::with('warneduser')->select(DB::raw('user_id, count(*) as value'))->where('active', '=', 1)->groupBy('user_id')->having('value', '>=', config('hitrun.max_warnings'))->get(); diff --git a/app/Console/Commands/AutoDisableInactiveUsers.php b/app/Console/Commands/AutoDisableInactiveUsers.php index bd38e5ed6..eec403857 100644 --- a/app/Console/Commands/AutoDisableInactiveUsers.php +++ b/app/Console/Commands/AutoDisableInactiveUsers.php @@ -45,9 +45,7 @@ class AutoDisableInactiveUsers extends Command public function handle() { if (config('pruning.user_pruning') == true) { - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); $current = Carbon::now(); diff --git a/app/Console/Commands/AutoRevokePermissions.php b/app/Console/Commands/AutoRevokePermissions.php index 4e42c03df..af67dd5d0 100644 --- a/app/Console/Commands/AutoRevokePermissions.php +++ b/app/Console/Commands/AutoRevokePermissions.php @@ -44,21 +44,11 @@ class AutoRevokePermissions extends Command */ public function handle() { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $leech_group = cache()->rememberForever('leech_group', function () { - return Group::where('slug', '=', 'leech')->pluck('id'); - }); - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); - $pruned_group = cache()->rememberForever('pruned_group', function () { - return Group::where('slug', '=', 'pruned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $leech_group = cache()->rememberForever('leech_group', fn() => Group::where('slug', '=', 'leech')->pluck('id')); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); + $pruned_group = cache()->rememberForever('pruned_group', fn() => Group::where('slug', '=', 'pruned')->pluck('id')); User::whereNotIn('group_id', [$banned_group[0], $validating_group[0], $leech_group[0], $disabled_group[0], $pruned_group[0]])->update(['can_download' => '1', 'can_request' => '1']); User::whereIn('group_id', [$banned_group[0], $validating_group[0], $leech_group[0], $disabled_group[0], $pruned_group[0]])->update(['can_download' => '0', 'can_request' => '0']); diff --git a/app/Console/Commands/AutoSoftDeleteDisabledUsers.php b/app/Console/Commands/AutoSoftDeleteDisabledUsers.php index 5d66cbe27..eca2b6a76 100644 --- a/app/Console/Commands/AutoSoftDeleteDisabledUsers.php +++ b/app/Console/Commands/AutoSoftDeleteDisabledUsers.php @@ -45,12 +45,8 @@ class AutoSoftDeleteDisabledUsers extends Command public function handle() { if (config('pruning.user_pruning') == true) { - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); - $pruned_group = cache()->rememberForever('pruned_group', function () { - return Group::where('slug', '=', 'pruned')->pluck('id'); - }); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); + $pruned_group = cache()->rememberForever('pruned_group', fn() => Group::where('slug', '=', 'pruned')->pluck('id')); $current = Carbon::now(); $users = User::where('group_id', '=', $disabled_group[0]) diff --git a/app/Helpers/BBCodeConverter.php b/app/Helpers/BBCodeConverter.php index c6f23109f..902418d23 100644 --- a/app/Helpers/BBCodeConverter.php +++ b/app/Helpers/BBCodeConverter.php @@ -32,9 +32,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[size=([\W\D\w\s]*?)\]([\W\D\w\s]*?)\[/size\]%iu', - function ($matches) { - return ''.trim($matches[1], '').''; - }, + fn($matches) => ''.trim($matches[1], '').'', $this->text ); @@ -47,9 +45,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[center\]([\W\D\w\s]*?)\[/center\]%iu', - function ($matches) { - return ''.trim($matches[1], ' ').''; - }, + fn($matches) => ''.trim($matches[1], ' ').'', $this->text ); @@ -62,9 +58,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[b\]([\W\D\w\s]*?)\[/b\]%iu', - function ($matches) { - return '**'.trim($matches[1], ' ').'**'; - }, + fn($matches) => '**'.trim($matches[1], ' ').'**', $this->text ); @@ -77,9 +71,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[i\]([\W\D\w\s]*?)\[/i\]%iu', - function ($matches) { - return '*'.trim($matches[1], ' ').'*'; - }, + fn($matches) => '*'.trim($matches[1], ' ').'*', $this->text ); @@ -92,9 +84,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[u\]([\W\D\w\s]*?)\[/u\]%iu', - function ($matches) { - return '_'.trim($matches[1], ' ').'_'; - }, + fn($matches) => '_'.trim($matches[1], ' ').'_', $this->text ); @@ -107,9 +97,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[s\]([\W\D\w\s]*?)\[/s\]%iu', - function ($matches) { - return '~~'.trim($matches[1], ' ').'~~'; - }, + fn($matches) => '~~'.trim($matches[1], ' ').'~~', $this->text ); @@ -170,9 +158,7 @@ class BBCodeConverter $columns = $matches['columns']; $columns = trim($columns); - $cells = preg_replace_callback('%\[td?\](?P[\W\w\s]*?)\[/td\]%iu', function ($matches) { - return $matches['cells'].' | '; - }, $columns); + $cells = preg_replace_callback('%\[td?\](?P[\W\w\s]*?)\[/td\]%iu', fn($matches) => $matches['cells'].' | ', $columns); if ($cells !== '') { $cells = '| '.$cells; @@ -239,9 +225,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[img\]([\W\D\w\s]*?)\[/img\]%iu', - function ($matches) { - return PHP_EOL.'![]'.'('.$matches[1].')'.PHP_EOL; - }, + fn($matches) => PHP_EOL.'![]'.'('.$matches[1].')'.PHP_EOL, $this->text ); @@ -254,9 +238,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[img\s*=\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\[/img\]%iu', - function ($matches) { - return PHP_EOL.'!['.$matches[2].']'.'('.$matches[1].')'.PHP_EOL; - }, + fn($matches) => PHP_EOL.'!['.$matches[2].']'.'('.$matches[1].')'.PHP_EOL, $this->text ); @@ -337,9 +319,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[spoiler\]([\W\D\w\s]*?)\[/spoiler\]%iu', - function ($matches) { - return '
Spoiler!
'.trim($matches[1], ' ').'
'; - }, + fn($matches) => '
Spoiler!
'.trim($matches[1], ' ').'
', $this->text ); @@ -352,9 +332,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[color=([\W\D\w\s]*?)\]([\W\D\w\s]*?)\[/color\]%iu', - function ($matches) { - return ''.trim($matches[1], '').''; - }, + fn($matches) => ''.trim($matches[1], '').'', $this->text ); @@ -367,9 +345,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[video=.*\]([\W\D\w\s]*?)\[/video\]%iu', - function ($matches) { - return ''; - }, + fn($matches) => '', $this->text ); @@ -382,9 +358,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[youtube\]([\W\D\w\s]*?)\[/youtube\]%iu', - function ($matches) { - return ''; - }, + fn($matches) => '', $this->text ); @@ -397,9 +371,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[alert\]([\W\D\w\s]*?)\[/alert\]%iu', - function ($matches) { - return '
'.trim($matches[1], '').'
'; - }, + fn($matches) => '
'.trim($matches[1], '').'
', $this->text ); @@ -412,9 +384,7 @@ class BBCodeConverter { $this->text = preg_replace_callback('%\[note\]([\W\D\w\s]*?)\[/note\]%iu', - function ($matches) { - return '
'.trim($matches[1], '').'
'; - }, + fn($matches) => '
'.trim($matches[1], '').'
', $this->text ); diff --git a/app/Http/Controllers/AnnounceController.php b/app/Http/Controllers/AnnounceController.php index 46d5a7c5e..affb4ee22 100644 --- a/app/Http/Controllers/AnnounceController.php +++ b/app/Http/Controllers/AnnounceController.php @@ -136,15 +136,9 @@ class AnnounceController extends Controller } // Caached System Required Groups - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); // If User Is Banned Return Error to Client if ($user->group_id == $banned_group[0]) { diff --git a/app/Http/Controllers/Auth/ActivationController.php b/app/Http/Controllers/Auth/ActivationController.php index 906e9247b..d2ed76b77 100644 --- a/app/Http/Controllers/Auth/ActivationController.php +++ b/app/Http/Controllers/Auth/ActivationController.php @@ -21,12 +21,8 @@ class ActivationController extends Controller { public function activate($token) { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $member_group = cache()->rememberForever('member_group', function () { - return Group::where('slug', '=', 'user')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $member_group = cache()->rememberForever('member_group', fn() => Group::where('slug', '=', 'user')->pluck('id')); $activation = UserActivation::with('user')->where('token', '=', $token)->firstOrFail(); if ($activation->user->id && $activation->user->group->id != $banned_group[0]) { diff --git a/app/Http/Controllers/Auth/ApplicationController.php b/app/Http/Controllers/Auth/ApplicationController.php index 1eeee726b..b27a6fc32 100644 --- a/app/Http/Controllers/Auth/ApplicationController.php +++ b/app/Http/Controllers/Auth/ApplicationController.php @@ -122,14 +122,10 @@ class ApplicationController extends Controller } $application->save(); // Map And Save IMG Proofs - $imgs = collect($request->input('images'))->map(function ($value) { - return new ApplicationImageProof(['image' => $value]); - }); + $imgs = collect($request->input('images'))->map(fn($value) => new ApplicationImageProof(['image' => $value])); $application->imageProofs()->saveMany($imgs); // Map And Save URL Proofs - $urls = collect($request->input('links'))->map(function ($value) { - return new ApplicationUrlProof(['url' => $value]); - }); + $urls = collect($request->input('links'))->map(fn($value) => new ApplicationUrlProof(['url' => $value])); $application->urlProofs()->saveMany($urls); return redirect()->route('login') diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 0301c7965..0bbea338c 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -69,18 +69,10 @@ class LoginController extends Controller protected function authenticated(Request $request, $user) { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); - $member_group = cache()->rememberForever('member_group', function () { - return Group::where('slug', '=', 'user')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); + $member_group = cache()->rememberForever('member_group', fn() => Group::where('slug', '=', 'user')->pluck('id')); if ($user->active == 0 || $user->group_id == $validating_group[0]) { $this->guard()->logout(); diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index cb28b7727..bbcce77aa 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -78,9 +78,7 @@ class RegisterController extends Controller ->withErrors(trans('auth.invalid-key')); } - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); $user = new User(); $user->username = $request->input('username'); diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index ce6b4fbfd..d244c0f48 100755 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -32,12 +32,8 @@ class ResetPasswordController extends Controller protected function resetPassword($user, $password) { - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $member_group = cache()->rememberForever('member_group', function () { - return Group::where('slug', '=', 'user')->pluck('id'); - }); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $member_group = cache()->rememberForever('member_group', fn() => Group::where('slug', '=', 'user')->pluck('id')); $user->password = bcrypt($password); $user->remember_token = Str::random(60); diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 764e7bae9..e4491dc78 100755 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -50,111 +50,83 @@ class HomeController extends Controller $user = $request->user(); // Latest Articles/News Block - $articles = cache()->remember('latest_article', $expiresAt, function () { - return Article::latest()->take(1)->get(); - }); + $articles = cache()->remember('latest_article', $expiresAt, fn() => Article::latest()->take(1)->get()); // Latest Torrents Block $personal_freeleech = PersonalFreeleech::where('user_id', '=', $user->id)->first(); - $newest = cache()->remember('newest_torrents', $expiresAt, function () { - return Torrent::with(['user', 'category']) - ->withCount(['thanks', 'comments']) - ->latest() - ->take(5) - ->get(); - }); + $newest = cache()->remember('newest_torrents', $expiresAt, fn() => Torrent::with(['user', 'category']) + ->withCount(['thanks', 'comments']) + ->latest() + ->take(5) + ->get()); - $seeded = cache()->remember('seeded_torrents', $expiresAt, function () { - return Torrent::with(['user', 'category']) - ->withCount(['thanks', 'comments']) - ->latest('seeders') - ->take(5) - ->get(); - }); + $seeded = cache()->remember('seeded_torrents', $expiresAt, fn() => Torrent::with(['user', 'category']) + ->withCount(['thanks', 'comments']) + ->latest('seeders') + ->take(5) + ->get()); - $leeched = cache()->remember('leeched_torrents', $expiresAt, function () { - return Torrent::with(['user', 'category']) - ->withCount(['thanks', 'comments']) - ->latest('leechers') - ->take(5) - ->get(); - }); + $leeched = cache()->remember('leeched_torrents', $expiresAt, fn() => Torrent::with(['user', 'category']) + ->withCount(['thanks', 'comments']) + ->latest('leechers') + ->take(5) + ->get()); - $dying = cache()->remember('dying_torrents', $expiresAt, function () { - return Torrent::with(['user', 'category']) - ->withCount(['thanks', 'comments']) - ->where('seeders', '=', 1) - ->where('times_completed', '>=', 1) - ->latest('leechers') - ->take(5) - ->get(); - }); + $dying = cache()->remember('dying_torrents', $expiresAt, fn() => Torrent::with(['user', 'category']) + ->withCount(['thanks', 'comments']) + ->where('seeders', '=', 1) + ->where('times_completed', '>=', 1) + ->latest('leechers') + ->take(5) + ->get()); - $dead = cache()->remember('dead_torrents', $expiresAt, function () { - return Torrent::with(['user', 'category']) - ->withCount(['thanks', 'comments']) - ->where('seeders', '=', 0) - ->latest('leechers') - ->take(5) - ->get(); - }); + $dead = cache()->remember('dead_torrents', $expiresAt, fn() => Torrent::with(['user', 'category']) + ->withCount(['thanks', 'comments']) + ->where('seeders', '=', 0) + ->latest('leechers') + ->take(5) + ->get()); // Latest Topics Block - $topics = cache()->remember('latest_topics', $expiresAt, function () { - return Topic::with('forum')->latest()->take(5)->get(); - }); + $topics = cache()->remember('latest_topics', $expiresAt, fn() => Topic::with('forum')->latest()->take(5)->get()); // Latest Posts Block - $posts = cache()->remember('latest_posts', $expiresAt, function () { - return Post::with('topic', 'user')->latest()->take(5)->get(); - }); + $posts = cache()->remember('latest_posts', $expiresAt, fn() => Post::with('topic', 'user')->latest()->take(5)->get()); // Online Block - $users = cache()->remember('online_users', $expiresAt, function () { - return User::with('group', 'privacy') - ->withCount([ - 'warnings' => function (Builder $query) { - $query->whereNotNull('torrent')->where('active', '1'); - }, - ]) - ->where('last_action', '>', now()->subMinutes(5)) - ->get(); - }); + $users = cache()->remember('online_users', $expiresAt, fn() => User::with('group', 'privacy') + ->withCount([ + 'warnings' => function (Builder $query) { + $query->whereNotNull('torrent')->where('active', '1'); + }, + ]) + ->where('last_action', '>', now()->subMinutes(5)) + ->get()); - $groups = cache()->remember('user-groups', $expiresAt, function () { - return Group::select(['name', 'color', 'effect', 'icon'])->oldest('position')->get(); - }); + $groups = cache()->remember('user-groups', $expiresAt, fn() => Group::select(['name', 'color', 'effect', 'icon'])->oldest('position')->get()); // Featured Torrents Block - $featured = cache()->remember('latest_featured', $expiresAt, function () { - return FeaturedTorrent::with('torrent')->get(); - }); + $featured = cache()->remember('latest_featured', $expiresAt, fn() => FeaturedTorrent::with('torrent')->get()); // Latest Poll Block - $poll = cache()->remember('latest_poll', $expiresAt, function () { - return Poll::latest()->first(); - }); + $poll = cache()->remember('latest_poll', $expiresAt, fn() => Poll::latest()->first()); // Top Uploaders Block - $uploaders = cache()->remember('top_uploaders', $expiresAt, function () { - return Torrent::with('user') - ->select(DB::raw('user_id, count(*) as value')) - ->groupBy('user_id') - ->latest('value') - ->take(10) - ->get(); - }); + $uploaders = cache()->remember('top_uploaders', $expiresAt, fn() => Torrent::with('user') + ->select(DB::raw('user_id, count(*) as value')) + ->groupBy('user_id') + ->latest('value') + ->take(10) + ->get()); - $past_uploaders = cache()->remember('month_uploaders', $expiresAt, function () use ($current) { - return Torrent::with('user') - ->where('created_at', '>', $current->copy()->subDays(30)->toDateTimeString()) - ->select(DB::raw('user_id, count(*) as value')) - ->groupBy('user_id') - ->latest('value') - ->take(10) - ->get(); - }); + $past_uploaders = cache()->remember('month_uploaders', $expiresAt, fn() => Torrent::with('user') + ->where('created_at', '>', $current->copy()->subDays(30)->toDateTimeString()) + ->select(DB::raw('user_id, count(*) as value')) + ->groupBy('user_id') + ->latest('value') + ->take(10) + ->get()); $freeleech_tokens = FreeleechToken::where('user_id', $user->id)->get(); $bookmarks = Bookmark::where('user_id', $user->id)->get(); diff --git a/app/Http/Controllers/RssController.php b/app/Http/Controllers/RssController.php index 44457d7f3..2903a277e 100644 --- a/app/Http/Controllers/RssController.php +++ b/app/Http/Controllers/RssController.php @@ -149,12 +149,8 @@ class RssController extends Controller { $user = User::where('rsskey', '=', (string) $rsskey)->firstOrFail(); - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); if ($user->group->id == $banned_group[0]) { abort(404); diff --git a/app/Http/Controllers/Staff/BanController.php b/app/Http/Controllers/Staff/BanController.php index 01be2a626..0000e4b85 100644 --- a/app/Http/Controllers/Staff/BanController.php +++ b/app/Http/Controllers/Staff/BanController.php @@ -51,9 +51,7 @@ class BanController extends Controller { $user = User::where('username', '=', $username)->firstOrFail(); $staff = $request->user(); - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); abort_if($user->group->is_modo || $request->user()->id == $user->id, 403); diff --git a/app/Http/Controllers/Staff/HomeController.php b/app/Http/Controllers/Staff/HomeController.php index 337289dd6..d865cdbf6 100644 --- a/app/Http/Controllers/Staff/HomeController.php +++ b/app/Http/Controllers/Staff/HomeController.php @@ -38,12 +38,8 @@ class HomeController extends Controller public function index(Request $request) { // User Info - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); $num_user = User::count(); $banned = User::where('group_id', '=', $banned_group[0])->count(); $validating = User::where('group_id', '=', $validating_group[0])->count(); diff --git a/app/Http/Controllers/Staff/MassActionController.php b/app/Http/Controllers/Staff/MassActionController.php index acf95600c..1e1d415e4 100644 --- a/app/Http/Controllers/Staff/MassActionController.php +++ b/app/Http/Controllers/Staff/MassActionController.php @@ -75,12 +75,8 @@ class MassActionController extends Controller */ public function update() { - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $member_group = cache()->rememberForever('member_group', function () { - return Group::where('slug', '=', 'user')->pluck('id'); - }); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $member_group = cache()->rememberForever('member_group', fn() => Group::where('slug', '=', 'user')->pluck('id')); $users = User::where('group_id', '=', $validating_group[0])->get(); foreach ($users as $user) { diff --git a/app/Http/Controllers/Staff/PollController.php b/app/Http/Controllers/Staff/PollController.php index e5a55ecaf..fdb90932a 100644 --- a/app/Http/Controllers/Staff/PollController.php +++ b/app/Http/Controllers/Staff/PollController.php @@ -85,9 +85,7 @@ class PollController extends Controller $poll = $request->user() ? $user->polls()->create($request->all()) : Poll::create($request->all()); - $options = collect($request->input('options'))->map(function ($value) { - return new Option(['name' => $value]); - }); + $options = collect($request->input('options'))->map(fn($value) => new Option(['name' => $value])); $poll->options()->saveMany($options); $poll_url = hrefPoll($poll); @@ -135,13 +133,9 @@ class PollController extends Controller } // Remove the deleted options in poll - $oldOptionIds = collect($poll->options)->map(function ($option) { - return $option->id; - })->all(); + $oldOptionIds = collect($poll->options)->map(fn($option) => $option->id)->all(); - $existingOldOptionIds = collect($request->input('option-id'))->map(function ($id) { - return intval($id); - })->all(); + $existingOldOptionIds = collect($request->input('option-id'))->map(fn($id) => intval($id))->all(); $idsOfOptionToBeRemove = array_diff($oldOptionIds, $existingOldOptionIds); @@ -151,9 +145,7 @@ class PollController extends Controller } // Update existing options - $existingOldOptionContents = collect($request->input('option-content'))->map(function ($content) { - return strval($content); - })->all(); + $existingOldOptionContents = collect($request->input('option-content'))->map(fn($content) => strval($content))->all(); if (count($existingOldOptionContents) === count($existingOldOptionIds)) { $len = count($existingOldOptionContents); @@ -165,9 +157,7 @@ class PollController extends Controller } // Insert new options - $newOptions = collect($request->input('new-option-content'))->map(function ($content) { - return new Option(['name' => $content]); - }); + $newOptions = collect($request->input('new-option-content'))->map(fn($content) => new Option(['name' => $content])); $poll->options()->saveMany($newOptions); diff --git a/app/Http/Controllers/StatsController.php b/app/Http/Controllers/StatsController.php index 54a894a22..f91f9c042 100644 --- a/app/Http/Controllers/StatsController.php +++ b/app/Http/Controllers/StatsController.php @@ -44,112 +44,74 @@ class StatsController extends Controller public function index() { // Total Members Count (All Groups) - $all_user = cache()->remember('all_user', $this->expiresAt, function () { - return User::withTrashed()->count(); - }); + $all_user = cache()->remember('all_user', $this->expiresAt, fn() => User::withTrashed()->count()); // Total Active Members Count (Not Validating, Banned, Disabled, Pruned) $active_user = cache()->remember('active_user', $this->expiresAt, function () { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); - $pruned_group = cache()->rememberForever('pruned_group', function () { - return Group::where('slug', '=', 'pruned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); + $pruned_group = cache()->rememberForever('pruned_group', fn() => Group::where('slug', '=', 'pruned')->pluck('id')); return User::whereNotIn('group_id', [$validating_group[0], $banned_group[0], $disabled_group[0], $pruned_group[0]])->count(); }); // Total Disabled Members Count $disabled_user = cache()->remember('disabled_user', $this->expiresAt, function () { - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); return User::where('group_id', '=', $disabled_group[0])->count(); }); // Total Pruned Members Count $pruned_user = cache()->remember('pruned_user', $this->expiresAt, function () { - $pruned_group = cache()->rememberForever('pruned_group', function () { - return Group::where('slug', '=', 'pruned')->pluck('id'); - }); + $pruned_group = cache()->rememberForever('pruned_group', fn() => Group::where('slug', '=', 'pruned')->pluck('id')); return User::onlyTrashed()->where('group_id', '=', $pruned_group[0])->count(); }); // Total Banned Members Count $banned_user = cache()->remember('banned_user', $this->expiresAt, function () { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); return User::where('group_id', '=', $banned_group[0])->count(); }); // Total Torrents Count - $num_torrent = cache()->remember('num_torrent', $this->expiresAt, function () { - return Torrent::count(); - }); + $num_torrent = cache()->remember('num_torrent', $this->expiresAt, fn() => Torrent::count()); // Total Categories With Torrent Count $categories = Category::withCount('torrents')->get()->sortBy('position'); // Total HD Count - $num_hd = cache()->remember('num_hd', $this->expiresAt, function () { - return Torrent::where('sd', '=', 0)->count(); - }); + $num_hd = cache()->remember('num_hd', $this->expiresAt, fn() => Torrent::where('sd', '=', 0)->count()); // Total SD Count - $num_sd = cache()->remember('num_sd', $this->expiresAt, function () { - return Torrent::where('sd', '=', 1)->count(); - }); + $num_sd = cache()->remember('num_sd', $this->expiresAt, fn() => Torrent::where('sd', '=', 1)->count()); // Total Torrent Size - $torrent_size = cache()->remember('torrent_size', $this->expiresAt, function () { - return Torrent::sum('size'); - }); + $torrent_size = cache()->remember('torrent_size', $this->expiresAt, fn() => Torrent::sum('size')); // Total Seeders - $num_seeders = cache()->remember('num_seeders', $this->expiresAt, function () { - return Peer::where('seeder', '=', 1)->count(); - }); + $num_seeders = cache()->remember('num_seeders', $this->expiresAt, fn() => Peer::where('seeder', '=', 1)->count()); // Total Leechers - $num_leechers = cache()->remember('num_leechers', $this->expiresAt, function () { - return Peer::where('seeder', '=', 0)->count(); - }); + $num_leechers = cache()->remember('num_leechers', $this->expiresAt, fn() => Peer::where('seeder', '=', 0)->count()); // Total Peers - $num_peers = cache()->remember('num_peers', $this->expiresAt, function () { - return Peer::count(); - }); + $num_peers = cache()->remember('num_peers', $this->expiresAt, fn() => Peer::count()); //Total Upload Traffic Without Double Upload - $actual_upload = cache()->remember('actual_upload', $this->expiresAt, function () { - return History::sum('actual_uploaded'); - }); + $actual_upload = cache()->remember('actual_upload', $this->expiresAt, fn() => History::sum('actual_uploaded')); //Total Upload Traffic With Double Upload - $credited_upload = cache()->remember('credited_upload', $this->expiresAt, function () { - return History::sum('uploaded'); - }); + $credited_upload = cache()->remember('credited_upload', $this->expiresAt, fn() => History::sum('uploaded')); //Total Download Traffic Without Freeleech - $actual_download = cache()->remember('actual_download', $this->expiresAt, function () { - return History::sum('actual_downloaded'); - }); + $actual_download = cache()->remember('actual_download', $this->expiresAt, fn() => History::sum('actual_downloaded')); //Total Download Traffic With Freeleech - $credited_download = cache()->remember('credited_download', $this->expiresAt, function () { - return History::sum('downloaded'); - }); + $credited_download = cache()->remember('credited_download', $this->expiresAt, fn() => History::sum('downloaded')); //Total Up/Down Traffic without perks $actual_up_down = $actual_upload + $actual_download; @@ -189,18 +151,10 @@ class StatsController extends Controller */ public function uploaded() { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); - $pruned_group = cache()->rememberForever('pruned_group', function () { - return Group::where('slug', '=', 'pruned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); + $pruned_group = cache()->rememberForever('pruned_group', fn() => Group::where('slug', '=', 'pruned')->pluck('id')); // Fetch Top Uploaders $uploaded = User::latest('uploaded')->whereNotIn('group_id', [$validating_group[0], $banned_group[0], $disabled_group[0], $pruned_group[0]])->take(100)->get(); @@ -217,18 +171,10 @@ class StatsController extends Controller */ public function downloaded() { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); - $pruned_group = cache()->rememberForever('pruned_group', function () { - return Group::where('slug', '=', 'pruned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); + $pruned_group = cache()->rememberForever('pruned_group', fn() => Group::where('slug', '=', 'pruned')->pluck('id')); // Fetch Top Downloaders $downloaded = User::latest('downloaded')->whereNotIn('group_id', [$validating_group[0], $banned_group[0], $disabled_group[0], $pruned_group[0]])->take(100)->get(); @@ -284,18 +230,10 @@ class StatsController extends Controller */ public function bankers() { - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); - $validating_group = cache()->rememberForever('validating_group', function () { - return Group::where('slug', '=', 'validating')->pluck('id'); - }); - $disabled_group = cache()->rememberForever('disabled_group', function () { - return Group::where('slug', '=', 'disabled')->pluck('id'); - }); - $pruned_group = cache()->rememberForever('pruned_group', function () { - return Group::where('slug', '=', 'pruned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); + $validating_group = cache()->rememberForever('validating_group', fn() => Group::where('slug', '=', 'validating')->pluck('id')); + $disabled_group = cache()->rememberForever('disabled_group', fn() => Group::where('slug', '=', 'disabled')->pluck('id')); + $pruned_group = cache()->rememberForever('pruned_group', fn() => Group::where('slug', '=', 'pruned')->pluck('id')); // Fetch Top Bankers $bankers = User::latest('seedbonus')->whereNotIn('group_id', [$validating_group[0], $banned_group[0], $disabled_group[0], $pruned_group[0]])->take(100)->get(); diff --git a/app/Http/Middleware/CheckIfBanned.php b/app/Http/Middleware/CheckIfBanned.php index e0bea7205..2cabc7021 100644 --- a/app/Http/Middleware/CheckIfBanned.php +++ b/app/Http/Middleware/CheckIfBanned.php @@ -32,9 +32,7 @@ class CheckIfBanned public function handle($request, Closure $next, $guard = null) { $user = $request->user(); - $banned_group = cache()->rememberForever('banned_group', function () { - return Group::where('slug', '=', 'banned')->pluck('id'); - }); + $banned_group = cache()->rememberForever('banned_group', fn() => Group::where('slug', '=', 'banned')->pluck('id')); if ($user && $user->group_id == $banned_group[0]) { auth()->logout(); diff --git a/app/Http/Middleware/Http2ServerPush.php b/app/Http/Middleware/Http2ServerPush.php index 147fad874..95396ff60 100644 --- a/app/Http/Middleware/Http2ServerPush.php +++ b/app/Http/Middleware/Http2ServerPush.php @@ -82,17 +82,13 @@ class Http2ServerPush $excludeKeywords ?? $this->getConfig('exclude_keywords', []); $headers = $this->fetchLinkableNodes($response) ->flatten(1) - ->map(function ($url) { - return $this->buildLinkHeaderString($url); - }) + ->map(fn($url) => $this->buildLinkHeaderString($url)) ->unique() ->filter(function ($value, $key) use ($excludeKeywords) { if (!$value) { return false; } - $exclude_keywords = collect($excludeKeywords)->map(function ($keyword) { - return preg_quote($keyword); - }); + $exclude_keywords = collect($excludeKeywords)->map(fn($keyword) => preg_quote($keyword)); if ($exclude_keywords->count() <= 0) { return true; } @@ -154,9 +150,7 @@ class Http2ServerPush */ private function buildLinkHeaderString($url) { - $type = collect(self::LINK_TYPE_MAP)->first(function ($type, $extension) use ($url) { - return Str::contains(strtoupper($url), $extension); - }); + $type = collect(self::LINK_TYPE_MAP)->first(fn($type, $extension) => Str::contains(strtoupper($url), $extension)); if (!preg_match('%^https?://%i', $url)) { $basePath = $this->getConfig('base_path', '/'); $url = $basePath.ltrim($url, $basePath); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 650b8e576..a5e67578c 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -75,17 +75,13 @@ class AppServiceProvider extends ServiceProvider // Share $footer_pages across all views view()->composer('*', function (View $view) { - $footer_pages = cache()->remember('cached-pages', 3_600, function () { - return Page::select(['id', 'name', 'slug', 'created_at'])->take(6)->get(); - }); + $footer_pages = cache()->remember('cached-pages', 3_600, fn() => Page::select(['id', 'name', 'slug', 'created_at'])->take(6)->get()); $view->with(compact('footer_pages')); }); // Hidden Captcha - Blade::directive('hiddencaptcha', function ($mustBeEmptyField = '_username') { - return sprintf('', $mustBeEmptyField); - }); + Blade::directive('hiddencaptcha', fn($mustBeEmptyField = '_username') => sprintf('', $mustBeEmptyField)); $this->app['validator']->extendImplicit( 'hiddencaptcha', diff --git a/app/Services/Clients/Client.php b/app/Services/Clients/Client.php index 7c6c42508..1ab5c80db 100755 --- a/app/Services/Clients/Client.php +++ b/app/Services/Clients/Client.php @@ -67,9 +67,7 @@ abstract class Client $key = 'movietvdb:'.$key; if ($data) { - cache()->remember($key, 7 * 24 * 60, function () use ($data) { - return serialize($data); - }); + cache()->remember($key, 7 * 24 * 60, fn() => serialize($data)); } if (cache()->has($key)) { diff --git a/app/Services/Clients/TmdbClient.php b/app/Services/Clients/TmdbClient.php index c73558185..6597caf70 100755 --- a/app/Services/Clients/TmdbClient.php +++ b/app/Services/Clients/TmdbClient.php @@ -335,13 +335,9 @@ class TmdbClient extends Client implements MovieTvInterface private function formatImages($images, $path, $image) { - $images = array_map(function ($item) use ($path) { - return $path.$item['file_path']; - }, $images); + $images = array_map(fn($item) => $path.$item['file_path'], $images); - return array_filter($images, function ($item) use ($path, $image) { - return !($item == $path.$image); - }); + return array_filter($images, fn($item) => !($item == $path.$image)); } private function formatCasts($credits, $role)