mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
feat: refactor code and improve readability
This commit is contained in:
@@ -13,10 +13,8 @@ class UserCreateCommand extends Command
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
if (config('app.env') === 'production') {
|
||||
if (! $this->confirm('You are in production mode. Are you sure you want to continue?')) {
|
||||
return;
|
||||
}
|
||||
if (config('app.env') === 'production' && ! $this->confirm('You are in production mode. Are you sure you want to continue?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->info('Creating a new user...');
|
||||
|
||||
@@ -24,7 +24,7 @@ function getAverageColorFromImageUrl($imageUrl): string
|
||||
|
||||
try {
|
||||
$img = $imgManager->read(file_get_contents($imageUrl));
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception) {
|
||||
return '#904f2c';
|
||||
}
|
||||
|
||||
@@ -90,9 +90,7 @@ function getChampionImage($full_id, $type): string
|
||||
function getCommitHash(): string
|
||||
{
|
||||
/** @var string $commit */
|
||||
$commit = Cache::remember('commit_hash', 60 * 72, function () {
|
||||
return trim(exec('git log --pretty="%h" -n1 HEAD'));
|
||||
});
|
||||
$commit = Cache::remember('commit_hash', 60 * 72, fn() => trim(exec('git log --pretty="%h" -n1 HEAD')));
|
||||
|
||||
return $commit;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,15 @@ class ContactSubmissionController extends Controller
|
||||
$descriptionContent = "**Name**: {$contactSubmission->name}\n\n**Email**: {$contactSubmission->email}\n\n**Category**: {$contactSubmission->category->humanReadable()}\n\n**Subject**: {$contactSubmission->subject}\n\n**Message**: {$contactSubmission->message}";
|
||||
|
||||
if ($contactSubmission->discord) {
|
||||
$descriptionContent .= "\n\n\n**Discord**: {$contactSubmission->discord}";
|
||||
$descriptionContent .= '
|
||||
|
||||
|
||||
**Discord**: ' . $contactSubmission->discord;
|
||||
}
|
||||
|
||||
DiscordAlert::message("There is a new contact submission from {$contactSubmission->name} ({$contactSubmission->email}).", [
|
||||
DiscordAlert::message(sprintf('There is a new contact submission from %s (%s).', $contactSubmission->name, $contactSubmission->email), [
|
||||
[
|
||||
'title' => "{$contactSubmission->category->humanReadable()} - {$contactSubmission->subject}",
|
||||
'title' => sprintf('%s - %s', $contactSubmission->category->humanReadable(), $contactSubmission->subject),
|
||||
'description' => $descriptionContent,
|
||||
'color' => '#ff8a4c',
|
||||
],
|
||||
|
||||
@@ -10,9 +10,7 @@ class PostsController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$posts = Sheets::all()->filter(function ($post) {
|
||||
return ! $post->hidden;
|
||||
})->sortByDesc('date');
|
||||
$posts = Sheets::all()->filter(fn($post) => ! $post->hidden)->sortByDesc('date');
|
||||
$paginatedPosts = Paginate::collection($posts, 6);
|
||||
|
||||
return view('posts.index', [
|
||||
|
||||
@@ -27,12 +27,12 @@ class SaleController extends Controller
|
||||
|
||||
return $response;
|
||||
});
|
||||
} catch (\Exception $e) {
|
||||
if ($e->getMessage() === 'Trying to access array offset on value of type null') {
|
||||
} catch (\Exception $exception) {
|
||||
if ($exception->getMessage() === 'Trying to access array offset on value of type null') {
|
||||
logger()->error('LMI has broken');
|
||||
abort(503, 'Sorry, the Sale Rotation is currently under maintenance. Please try again later.');
|
||||
} else {
|
||||
logger()->error('An error occurred while trying to fetch the Sale Rotation', ['error' => $e->getMessage()]);
|
||||
logger()->error('An error occurred while trying to fetch the Sale Rotation', ['error' => $exception->getMessage()]);
|
||||
abort(500, 'Sorry, an error occurred while trying to fetch the Sale Rotation. Please try again later.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ class ChampionRoles extends Model
|
||||
|
||||
public function getRolesAttribute($value): array
|
||||
{
|
||||
$value = json_decode($value);
|
||||
$value = json_decode((string) $value);
|
||||
|
||||
$roleNames = [
|
||||
'TOP' => 'Toplane',
|
||||
|
||||
@@ -28,11 +28,11 @@ class Streamer extends Model
|
||||
public function getStreamerUrlAttribute(): string
|
||||
{
|
||||
return match ($this->platform) {
|
||||
'Twitch' => "https://www.twitch.tv/{$this->username}",
|
||||
'YouTube' => "https://www.youtube.com/@{$this->username}",
|
||||
'Kick' => "https://kick.com/{$this->username}",
|
||||
'Douyu' => "https://www.douyu.com/{$this->username}",
|
||||
'Huya' => "https://www.huya.com/{$this->username}",
|
||||
'Twitch' => 'https://www.twitch.tv/' . $this->username,
|
||||
'YouTube' => 'https://www.youtube.com/@' . $this->username,
|
||||
'Kick' => 'https://kick.com/' . $this->username,
|
||||
'Douyu' => 'https://www.douyu.com/' . $this->username,
|
||||
'Huya' => 'https://www.huya.com/' . $this->username,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -46,21 +46,15 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
public function bootAuth(): void
|
||||
{
|
||||
Gate::define('viewPulse', function (User $user) {
|
||||
return $user->admin;
|
||||
});
|
||||
Gate::define('viewPulse', fn(User $user) => $user->admin);
|
||||
}
|
||||
|
||||
public function bootRoute(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request) {
|
||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||
});
|
||||
RateLimiter::for('api', fn(Request $request) => Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()));
|
||||
|
||||
Route::bind('post', function ($path) {
|
||||
return $this->app->make(Sheets::class)
|
||||
->collection('posts')
|
||||
->get($path) ?? abort(404);
|
||||
});
|
||||
Route::bind('post', fn($path) => $this->app->make(Sheets::class)
|
||||
->collection('posts')
|
||||
->get($path) ?? abort(404));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user