Skip to content

Commit

Permalink
cleanup: pint
Browse files Browse the repository at this point in the history
  • Loading branch information
blt950 committed Dec 29, 2024
1 parent 76a2a78 commit bb0d520
Show file tree
Hide file tree
Showing 42 changed files with 205 additions and 215 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/CreateApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public function handle()
'created_at' => now(),
]);

$this->comment('API key `' . $name . '` has been created with following token: `' . $secret . '`');
$this->comment('API key `'.$name.'` has been created with following token: `'.$secret.'`');
}
}
2 changes: 1 addition & 1 deletion app/Console/Commands/DatabaseCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Event;
use Illuminate\Console\Command;

class DatabaseCleanup extends Command
{
Expand Down
14 changes: 7 additions & 7 deletions app/Console/Commands/EventsNotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Event;
use App\Helpers\EventHelper;
use App\Models\Event;
use Carbon\Carbon;
use Illuminate\Console\Command;

class EventsNotify extends Command
{
Expand Down Expand Up @@ -36,9 +36,9 @@ public function handle()

// Notify about upcoming events
foreach ($events as $event) {

$result = EventHelper::discordPost(
EventHelper::discordMention() . "\n:clock2: **".$event->title.'** is starting in two hours!',
EventHelper::discordMention()."\n:clock2: **".$event->title.'** is starting in two hours!',
$event->title,
$event->long_description,
asset($event->image),
Expand All @@ -47,14 +47,14 @@ public function handle()
);

// Save the message as published
if($result) {
if ($result) {
$event->published = true;
$event->save();
}

$this->info('Notified about event: ' . $event->title);
$this->info('Notified about event: '.$event->title);
}

$this->info('Notified about ' . $events->count() . ' upcoming events');
$this->info('Notified about '.$events->count().' upcoming events');
}
}
7 changes: 3 additions & 4 deletions app/Console/Commands/NotifyCleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\Event;
use App\Helpers\EventHelper;
use App\Models\DiscordMessage;
use Illuminate\Console\Command;

class EventsCleanup extends Command
{
Expand Down Expand Up @@ -35,11 +34,11 @@ public function handle()
foreach ($messages as $message) {
// Delete the message
EventHelper::discordDelete($message->message_id);
$this->info('Cleaned up message: ' . $message->message_id);
$this->info('Cleaned up message: '.$message->message_id);
}

DiscordMessage::whereIn('message_id', $messages->pluck('message_id'))->delete();

$this->info('Cleaned up ' . $messages->count() . ' past events');
$this->info('Cleaned up '.$messages->count().' past events');
}
}
3 changes: 2 additions & 1 deletion app/Exceptions/PolicyMethodMissingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class PolicyMethodMissingException extends Exception
* @param null $message
* @param null $code
*/
public function __construct($message = null, $code = null, ?Exception $exception = null) {
public function __construct($message = null, $code = null, ?Exception $exception = null)
{
parent::__construct($message ?? 'The method does not exist in the policy.', 0, $exception);

$this->code = $code ?: 0;
Expand Down
3 changes: 2 additions & 1 deletion app/Exceptions/PolicyMissingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class PolicyMissingException extends Exception
* @param null $message
* @param null $code
*/
public function __construct($message = null, $code = null, ?Exception $exception) {
public function __construct($message, $code, ?Exception $exception)
{
parent::__construct($message ?? 'A policy does not exist for this model.', 0, $exception);

$this->code = $code ?: 0;
Expand Down
24 changes: 12 additions & 12 deletions app/Helpers/EventHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace App\Helpers;

use App\Models\DiscordMessage;
use Carbon\Carbon;
use Illuminate\Support\Facades\Http;
use App\Models\DiscordMessage;

enum EventHelper: string
enum EventHelper: string
{
case DAY = 'day';
case WEEK = 'week';
case MONTH = 'month';
case YEAR = 'year';

public static function labels() : array
public static function labels(): array
{
return [
self::DAY->value => 'Daily',
Expand All @@ -23,16 +23,16 @@ public static function labels() : array
];
}

public static function discordMention() : string
public static function discordMention(): string
{
if(config('discord.mention_role') === null) {
if (config('discord.mention_role') === null) {
return '';
}

return '<@&' . config('discord.mention_role') . '>';
return '<@&'.config('discord.mention_role').'>';
}

public static function discordPost( string $text, string $title, string $content, string $image = null, Carbon $timestamp, Carbon $expireMessageAt = null) : bool
public static function discordPost(string $text, string $title, string $content, ?string $image, Carbon $timestamp, ?Carbon $expireMessageAt = null): bool
{
$webhookUrl = config('discord.webhook');
$payload = [
Expand All @@ -56,11 +56,11 @@ public static function discordPost( string $text, string $title, string $content
];

// Send the message to Discord
$response = Http::post($webhookUrl."?wait=true", $payload);
$response = Http::post($webhookUrl.'?wait=true', $payload);
$messageId = $response->json()['id'] ?? null;

// Save the message for expiration
if($messageId !== null && $expireMessageAt !== null) {
if ($messageId !== null && $expireMessageAt !== null) {
DiscordMessage::create([
'message_id' => $messageId,
'expires_at' => $expireMessageAt,
Expand All @@ -70,9 +70,9 @@ public static function discordPost( string $text, string $title, string $content
return $messageId !== null;
}

public static function discordDelete(int $messageId) : void
public static function discordDelete(int $messageId): void
{
$webhookUrl = config('discord.webhook');
Http::delete($webhookUrl . "/messages/{$messageId}");
Http::delete($webhookUrl."/messages/{$messageId}");
}
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/API/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CalendarController extends Controller
public function index()
{
$calendars = Calendar::all();

return response()->json(['data' => $calendars->values()], 200);
}

Expand All @@ -25,7 +26,7 @@ public function store(Request $request)
$request->validate([
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'public' => 'required|boolean'
'public' => 'required|boolean',
]);

$calendar = Calendar::create([
Expand All @@ -45,7 +46,7 @@ public function store(Request $request)
*/
public function show(Calendar $calendar)
{
return response()->json(['calendar' => $calendar,], 200);
return response()->json(['calendar' => $calendar], 200);
}

/**
Expand Down
54 changes: 27 additions & 27 deletions app/Http/Controllers/API/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ class EventController extends Controller
/**
* Display a listing of the resource.
*/
public function index(Calendar $calendar)
public function index(Calendar $calendar)
{
$events = $calendar
->events()
->where('start_date', '>=', Carbon::today())
->orderBy('start_date', 'asc')
->get();


// Set the full path on the image attribute and add a full url to event
$events->transform(function ($event) {
$event->image = isset($event->image) ? asset('storage/banners/' . $event->image) : asset('images/tba.jpg');
$event->image = isset($event->image) ? asset('storage/banners/'.$event->image) : asset('images/tba.jpg');
$event->link = route('events.show', $event->id);

return $event;
});

Expand All @@ -37,7 +37,7 @@ public function index(Calendar $calendar)
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
public function store(Request $request)
{
$data = $this->validate($request, [
'calendar_id' => 'required|exists:calendars,id',
Expand All @@ -61,19 +61,19 @@ public function store(Request $request)

if ($request->hasFile('image')) {
$image = $request->file('image');
$imageName = now()->format('Y-m-d') . '-' . uniqid() . '.' . $image->getClientOriginalExtension();
$imageName = now()->format('Y-m-d').'-'.uniqid().'.'.$image->getClientOriginalExtension();

// Get image dimensions
list($width, $height) = getimagesize($image->getPathName());
[$width, $height] = getimagesize($image->getPathName());
if (round($width / $height, 2) != round(16 / 9, 2)) {
return back()->withErrors(['image' => 'Image must be in 16:9 aspect ratio.'])->withInput();
}

// Store the image
$storedPath = $image->storeAs('banners', $imageName, 'public');

// Check if the image was successfully uploaded
if (!$storedPath && !Storage::disk('public')->exists($storedPath)) {
if (! $storedPath && ! Storage::disk('public')->exists($storedPath)) {
return back()->withErrors(['image' => 'Failed to upload the image.'])->withInput();
}

Expand Down Expand Up @@ -111,10 +111,10 @@ public function store(Request $request)
/**
* Display the specified resource.
*/
public function show(Event $event)
public function show(Event $event)
{
// Set the full path on the image attribute and add a full url to event
$event->image = isset($event->image) ? asset('storage/banners/' . $event->image) : asset('images/tba.jpg');
$event->image = isset($event->image) ? asset('storage/banners/'.$event->image) : asset('images/tba.jpg');
$event->link = route('events.show', $event->id);

return response()->json(['event' => $event], 200);
Expand All @@ -123,7 +123,7 @@ public function show(Event $event)
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Event $event)
public function update(Request $request, Event $event)
{
$data = $this->validate($request, [
'calendar_id' => 'required|exists:calendars,id',
Expand All @@ -148,29 +148,29 @@ public function update(Request $request, Event $event)

if ($request->hasFile('image')) {
$image = $request->file('image');
$imageName = now()->format('Y-m-d') . '-' . uniqid() . '.' . $image->getClientOriginalExtension();
$imageName = now()->format('Y-m-d').'-'.uniqid().'.'.$image->getClientOriginalExtension();

// Get image dimensions
list($width, $height) = getimagesize($image->getPathName());
[$width, $height] = getimagesize($image->getPathName());
if (round($width / $height, 2) != round(16 / 9, 2)) {
return back()->withErrors(['image' => 'Image must be in 16:9 aspect ratio.']);
}

// Delete the old image if it exists
if ($event->image) {
Storage::disk('public')->delete('banners/' . $event->image);
Storage::disk('public')->delete('banners/'.$event->image);
}

// Store the new image
$image->storeAs('banners', $imageName, 'public');

// Check if the image was successfully uploaded
if (!Storage::disk('public')->exists('banners/' . $imageName)) {
if (! Storage::disk('public')->exists('banners/'.$imageName)) {
return back()->withErrors(['image' => 'Failed to upload the image.']);
}

$imageURL = asset('storage/banners/' . $imageName);
$imageURL = asset('storage/banners/'.$imageName);

$event->image = $imageURL;
}

Expand All @@ -180,7 +180,7 @@ public function update(Request $request, Event $event)
'short_description' => $request->input('short_description'),
'long_description' => $request->input('long_description'),
'start_date' => Carbon::parse($request->input('start_date'))->format('Y-m-d H:i'),
'end_date' => Carbon::parse($request->input('end_date'))->format('Y-m-d H:i'),
'end_date' => Carbon::parse($request->input('end_date'))->format('Y-m-d H:i'),
'recurrence_interval' => $request->input('event_type') == '0' ? null : $request->input('recurrence_interval'),
'recurrence_unit' => $request->input('event_type') == '0' ? null : $request->input('recurrence_unit'),
'recurrence_end_date' => $request->input('event_type') == '0' ? null : $request->input('recurrence_end_date'),
Expand Down Expand Up @@ -211,16 +211,16 @@ public function update(Request $request, Event $event)
/**
* Remove the specified resource from storage.
*/
public function destroy(Event $event)
public function destroy(Event $event)
{
// Delete the old image if it exists
if ($event->image && $event->parent_id === null) {
Storage::disk('public')->delete('banners/' . $event->image);
Storage::disk('public')->delete('banners/'.$event->image);
}

// Delete the event and any of its children
$event->children()->delete();

$event->delete();

return response()->json([
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct()
*/
public function login(Request $request)
{
if (!$request->has('code') || !$request->has('state')) {
if (! $request->has('code') || ! $request->has('state')) {
$authorizationUrl = $this->provider->getAuthorizationUrl([
'required_scopes' => implode(' ', config('oauth.scopes')),
'scope' => implode(' ', config('oauth.scopes')),
Expand Down Expand Up @@ -81,17 +81,17 @@ protected function verifyLogin(Request $request)
'code' => $request->input('code'),
]);
} catch (IdentityProviderException $e) {
return redirect()->route('home')->withError('Authentication error: ' . $e->getMessage());
return redirect()->route('home')->withError('Authentication error: '.$e->getMessage());
}

$resourceOwner = json_decode(json_encode($this->provider->getResourceOwner($accessToken)->toArray()));
$data = OAuthController::mapOAuthProperties($resourceOwner);

if (
!$data['id'] ||
!$data['email'] ||
!$data['first_name'] ||
!$data['last_name']
! $data['id'] ||
! $data['email'] ||
! $data['first_name'] ||
! $data['last_name']
) {
return redirect()->route('home')->withError('Missing data from sign-in request. You need to grant all permissions.');
}
Expand Down
Loading

0 comments on commit bb0d520

Please sign in to comment.