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
|
public function handle(): void
|
||||||
{
|
{
|
||||||
if (config('app.env') === 'production') {
|
if (config('app.env') === 'production' && ! $this->confirm('You are in production mode. Are you sure you want to continue?')) {
|
||||||
if (! $this->confirm('You are in production mode. Are you sure you want to continue?')) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info('Creating a new user...');
|
$this->info('Creating a new user...');
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function getAverageColorFromImageUrl($imageUrl): string
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$img = $imgManager->read(file_get_contents($imageUrl));
|
$img = $imgManager->read(file_get_contents($imageUrl));
|
||||||
} catch (Exception $e) {
|
} catch (Exception) {
|
||||||
return '#904f2c';
|
return '#904f2c';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +90,7 @@ function getChampionImage($full_id, $type): string
|
|||||||
function getCommitHash(): string
|
function getCommitHash(): string
|
||||||
{
|
{
|
||||||
/** @var string $commit */
|
/** @var string $commit */
|
||||||
$commit = Cache::remember('commit_hash', 60 * 72, function () {
|
$commit = Cache::remember('commit_hash', 60 * 72, fn() => trim(exec('git log --pretty="%h" -n1 HEAD')));
|
||||||
return trim(exec('git log --pretty="%h" -n1 HEAD'));
|
|
||||||
});
|
|
||||||
|
|
||||||
return $commit;
|
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}";
|
$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) {
|
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,
|
'description' => $descriptionContent,
|
||||||
'color' => '#ff8a4c',
|
'color' => '#ff8a4c',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ class PostsController extends Controller
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$posts = Sheets::all()->filter(function ($post) {
|
$posts = Sheets::all()->filter(fn($post) => ! $post->hidden)->sortByDesc('date');
|
||||||
return ! $post->hidden;
|
|
||||||
})->sortByDesc('date');
|
|
||||||
$paginatedPosts = Paginate::collection($posts, 6);
|
$paginatedPosts = Paginate::collection($posts, 6);
|
||||||
|
|
||||||
return view('posts.index', [
|
return view('posts.index', [
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ class SaleController extends Controller
|
|||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
});
|
});
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $exception) {
|
||||||
if ($e->getMessage() === 'Trying to access array offset on value of type null') {
|
if ($exception->getMessage() === 'Trying to access array offset on value of type null') {
|
||||||
logger()->error('LMI has broken');
|
logger()->error('LMI has broken');
|
||||||
abort(503, 'Sorry, the Sale Rotation is currently under maintenance. Please try again later.');
|
abort(503, 'Sorry, the Sale Rotation is currently under maintenance. Please try again later.');
|
||||||
} else {
|
} 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.');
|
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
|
public function getRolesAttribute($value): array
|
||||||
{
|
{
|
||||||
$value = json_decode($value);
|
$value = json_decode((string) $value);
|
||||||
|
|
||||||
$roleNames = [
|
$roleNames = [
|
||||||
'TOP' => 'Toplane',
|
'TOP' => 'Toplane',
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ class Streamer extends Model
|
|||||||
public function getStreamerUrlAttribute(): string
|
public function getStreamerUrlAttribute(): string
|
||||||
{
|
{
|
||||||
return match ($this->platform) {
|
return match ($this->platform) {
|
||||||
'Twitch' => "https://www.twitch.tv/{$this->username}",
|
'Twitch' => 'https://www.twitch.tv/' . $this->username,
|
||||||
'YouTube' => "https://www.youtube.com/@{$this->username}",
|
'YouTube' => 'https://www.youtube.com/@' . $this->username,
|
||||||
'Kick' => "https://kick.com/{$this->username}",
|
'Kick' => 'https://kick.com/' . $this->username,
|
||||||
'Douyu' => "https://www.douyu.com/{$this->username}",
|
'Douyu' => 'https://www.douyu.com/' . $this->username,
|
||||||
'Huya' => "https://www.huya.com/{$this->username}",
|
'Huya' => 'https://www.huya.com/' . $this->username,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,21 +46,15 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
public function bootAuth(): void
|
public function bootAuth(): void
|
||||||
{
|
{
|
||||||
Gate::define('viewPulse', function (User $user) {
|
Gate::define('viewPulse', fn(User $user) => $user->admin);
|
||||||
return $user->admin;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function bootRoute(): void
|
public function bootRoute(): void
|
||||||
{
|
{
|
||||||
RateLimiter::for('api', function (Request $request) {
|
RateLimiter::for('api', fn(Request $request) => Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()));
|
||||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
|
||||||
});
|
|
||||||
|
|
||||||
Route::bind('post', function ($path) {
|
Route::bind('post', fn($path) => $this->app->make(Sheets::class)
|
||||||
return $this->app->make(Sheets::class)
|
->collection('posts')
|
||||||
->collection('posts')
|
->get($path) ?? abort(404));
|
||||||
->get($path) ?? abort(404);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user