From 56db303b15c58c5f457fc29e10b0057557eeea4f Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sun, 8 Mar 2026 14:17:55 +0100 Subject: [PATCH] 25 - Fix code style issues across codebase with Pint --- app/Actions/CreateFeedAction.php | 2 +- app/Actions/CreatePlatformAccountAction.php | 2 +- .../Commands/FetchNewArticlesCommand.php | 4 ++-- app/Contracts/ArticleParserInterface.php | 3 ++- app/Contracts/HomepageParserInterface.php | 3 ++- app/Enums/PlatformEnum.php | 2 +- app/Events/ExceptionLogged.php | 3 +-- app/Events/ExceptionOccurred.php | 3 +-- app/Events/NewArticleFetched.php | 4 +--- app/Exceptions/ChannelException.php | 4 +--- app/Exceptions/PublishException.php | 2 +- app/Exceptions/RoutingException.php | 4 +--- app/Facades/LogSaver.php | 2 +- .../Controllers/Api/V1/ArticlesController.php | 9 ++++--- .../Controllers/Api/V1/AuthController.php | 11 ++++----- .../Controllers/Api/V1/FeedsController.php | 18 +++++++------- .../Controllers/Api/V1/KeywordsController.php | 12 +++++----- .../Controllers/Api/V1/LogsController.php | 2 +- .../Api/V1/PlatformAccountsController.php | 9 +++---- .../Controllers/Api/V1/RoutingController.php | 24 +++++++++---------- .../Controllers/Api/V1/SettingsController.php | 4 ++-- .../Middleware/EnsureOnboardingComplete.php | 2 +- app/Http/Middleware/HandleInertiaRequests.php | 2 +- .../RedirectIfOnboardingComplete.php | 4 ++-- app/Http/Requests/StoreFeedRequest.php | 4 ++-- app/Http/Requests/UpdateFeedRequest.php | 6 ++--- app/Jobs/ArticleDiscoveryForFeedJob.php | 8 +++---- app/Jobs/ArticleDiscoveryJob.php | 2 +- app/Jobs/PublishNextArticleJob.php | 15 ++++++------ app/Jobs/SyncChannelPostsJob.php | 10 ++++---- app/Listeners/LogExceptionToDatabase.php | 12 +++++----- app/Listeners/ValidateArticleListener.php | 1 + app/Providers/AppServiceProvider.php | 4 +--- config/feed.php | 2 +- config/languages.php | 2 +- .../factories/ArticlePublicationFactory.php | 4 ++-- database/factories/FeedFactory.php | 2 +- database/factories/KeywordFactory.php | 2 +- database/factories/LanguageFactory.php | 2 +- database/factories/PlatformAccountFactory.php | 4 ++-- database/factories/PlatformChannelFactory.php | 6 ++--- .../factories/PlatformInstanceFactory.php | 6 ++--- database/factories/RouteFactory.php | 4 ++-- database/factories/SettingFactory.php | 2 +- .../2024_01_01_000002_create_languages.php | 2 +- ...4_01_01_000004_create_feeds_and_routes.php | 2 +- database/seeders/LanguageSeeder.php | 2 +- database/seeders/PlatformInstanceSeeder.php | 17 +++++++------ database/seeders/SettingsSeeder.php | 1 - routes/api.php | 2 +- 50 files changed, 125 insertions(+), 134 deletions(-) diff --git a/app/Actions/CreateFeedAction.php b/app/Actions/CreateFeedAction.php index ac3ac62..ab76411 100644 --- a/app/Actions/CreateFeedAction.php +++ b/app/Actions/CreateFeedAction.php @@ -15,7 +15,7 @@ public function execute(string $name, string $provider, int $languageId, ?string $url = config("feed.providers.{$provider}.languages.{$langCode}.url"); - if (!$url) { + if (! $url) { throw new InvalidArgumentException("Invalid provider and language combination: {$provider}/{$langCode}"); } diff --git a/app/Actions/CreatePlatformAccountAction.php b/app/Actions/CreatePlatformAccountAction.php index e84e37d..2cf3d76 100644 --- a/app/Actions/CreatePlatformAccountAction.php +++ b/app/Actions/CreatePlatformAccountAction.php @@ -19,7 +19,7 @@ public function __construct( */ public function execute(string $instanceDomain, string $username, string $password, string $platform = 'lemmy'): PlatformAccount { - $fullInstanceUrl = 'https://' . $instanceDomain; + $fullInstanceUrl = 'https://'.$instanceDomain; // Authenticate first — if this fails, no records are created $authResponse = $this->lemmyAuthService->authenticate($fullInstanceUrl, $username, $password); diff --git a/app/Console/Commands/FetchNewArticlesCommand.php b/app/Console/Commands/FetchNewArticlesCommand.php index c0aef79..12bab5d 100644 --- a/app/Console/Commands/FetchNewArticlesCommand.php +++ b/app/Console/Commands/FetchNewArticlesCommand.php @@ -15,13 +15,13 @@ class FetchNewArticlesCommand extends Command public function handle(): int { - if (!Setting::isArticleProcessingEnabled()) { + if (! Setting::isArticleProcessingEnabled()) { $this->info('Article processing is disabled. Article discovery skipped.'); return self::SUCCESS; } - if (!Feed::where('is_active', true)->exists()) { + if (! Feed::where('is_active', true)->exists()) { $this->info('No active feeds found. Article discovery skipped.'); return self::SUCCESS; diff --git a/app/Contracts/ArticleParserInterface.php b/app/Contracts/ArticleParserInterface.php index ab6c89f..04917ad 100644 --- a/app/Contracts/ArticleParserInterface.php +++ b/app/Contracts/ArticleParserInterface.php @@ -11,6 +11,7 @@ public function canParse(string $url): bool; /** * Extract article data from HTML + * * @return array */ public function extractData(string $html): array; @@ -19,4 +20,4 @@ public function extractData(string $html): array; * Get the source name for this parser */ public function getSourceName(): string; -} \ No newline at end of file +} diff --git a/app/Contracts/HomepageParserInterface.php b/app/Contracts/HomepageParserInterface.php index 50301d6..c28b431 100644 --- a/app/Contracts/HomepageParserInterface.php +++ b/app/Contracts/HomepageParserInterface.php @@ -11,6 +11,7 @@ public function canParse(string $url): bool; /** * Extract article URLs from homepage HTML + * * @return array */ public function extractArticleUrls(string $html): array; @@ -24,4 +25,4 @@ public function getHomepageUrl(): string; * Get the source name for this parser */ public function getSourceName(): string; -} \ No newline at end of file +} diff --git a/app/Enums/PlatformEnum.php b/app/Enums/PlatformEnum.php index 689a532..50e1c96 100644 --- a/app/Enums/PlatformEnum.php +++ b/app/Enums/PlatformEnum.php @@ -5,4 +5,4 @@ enum PlatformEnum: string { case LEMMY = 'lemmy'; -} \ No newline at end of file +} diff --git a/app/Events/ExceptionLogged.php b/app/Events/ExceptionLogged.php index 702612a..518be13 100644 --- a/app/Events/ExceptionLogged.php +++ b/app/Events/ExceptionLogged.php @@ -12,6 +12,5 @@ class ExceptionLogged public function __construct( public Log $log - ) { - } + ) {} } diff --git a/app/Events/ExceptionOccurred.php b/app/Events/ExceptionOccurred.php index 79ea1cd..35a415e 100644 --- a/app/Events/ExceptionOccurred.php +++ b/app/Events/ExceptionOccurred.php @@ -17,6 +17,5 @@ public function __construct( public string $message, /** @var array */ public array $context = [] - ) { - } + ) {} } diff --git a/app/Events/NewArticleFetched.php b/app/Events/NewArticleFetched.php index 3e657f9..3635391 100644 --- a/app/Events/NewArticleFetched.php +++ b/app/Events/NewArticleFetched.php @@ -11,7 +11,5 @@ class NewArticleFetched { use Dispatchable, InteractsWithSockets, SerializesModels; - public function __construct(public Article $article) - { - } + public function __construct(public Article $article) {} } diff --git a/app/Exceptions/ChannelException.php b/app/Exceptions/ChannelException.php index 5f526b6..f04257e 100644 --- a/app/Exceptions/ChannelException.php +++ b/app/Exceptions/ChannelException.php @@ -4,6 +4,4 @@ use Exception; -class ChannelException extends Exception -{ -} +class ChannelException extends Exception {} diff --git a/app/Exceptions/PublishException.php b/app/Exceptions/PublishException.php index 250fb79..6cc7dcf 100644 --- a/app/Exceptions/PublishException.php +++ b/app/Exceptions/PublishException.php @@ -11,7 +11,7 @@ class PublishException extends Exception { public function __construct( private readonly Article $article, - private readonly PlatformEnum|null $platform, + private readonly ?PlatformEnum $platform, ?Throwable $previous = null ) { $message = "Failed to publish article #$article->id"; diff --git a/app/Exceptions/RoutingException.php b/app/Exceptions/RoutingException.php index acbc082..437aae0 100644 --- a/app/Exceptions/RoutingException.php +++ b/app/Exceptions/RoutingException.php @@ -4,6 +4,4 @@ use Exception; -class RoutingException extends Exception -{ -} +class RoutingException extends Exception {} diff --git a/app/Facades/LogSaver.php b/app/Facades/LogSaver.php index 661e618..eaa5d92 100644 --- a/app/Facades/LogSaver.php +++ b/app/Facades/LogSaver.php @@ -10,4 +10,4 @@ protected static function getFacadeAccessor() { return \App\Services\Log\LogSaver::class; } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Api/V1/ArticlesController.php b/app/Http/Controllers/Api/V1/ArticlesController.php index a1606c6..7fa1d97 100644 --- a/app/Http/Controllers/Api/V1/ArticlesController.php +++ b/app/Http/Controllers/Api/V1/ArticlesController.php @@ -3,13 +3,12 @@ namespace App\Http\Controllers\Api\V1; use App\Http\Resources\ArticleResource; +use App\Jobs\ArticleDiscoveryJob; use App\Models\Article; use App\Models\Setting; -use App\Jobs\ArticleDiscoveryJob; use Exception; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Artisan; class ArticlesController extends BaseController { @@ -54,7 +53,7 @@ public function approve(Article $article): JsonResponse 'Article approved and queued for publishing.' ); } catch (Exception $e) { - return $this->sendError('Failed to approve article: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to approve article: '.$e->getMessage(), [], 500); } } @@ -71,7 +70,7 @@ public function reject(Article $article): JsonResponse 'Article rejected.' ); } catch (Exception $e) { - return $this->sendError('Failed to reject article: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to reject article: '.$e->getMessage(), [], 500); } } @@ -88,7 +87,7 @@ public function refresh(): JsonResponse 'Article refresh started. New articles will appear shortly.' ); } catch (Exception $e) { - return $this->sendError('Failed to start article refresh: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to start article refresh: '.$e->getMessage(), [], 500); } } } diff --git a/app/Http/Controllers/Api/V1/AuthController.php b/app/Http/Controllers/Api/V1/AuthController.php index 8f336e0..d1f76b8 100644 --- a/app/Http/Controllers/Api/V1/AuthController.php +++ b/app/Http/Controllers/Api/V1/AuthController.php @@ -5,7 +5,6 @@ use App\Models\User; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Validation\ValidationException; @@ -24,7 +23,7 @@ public function login(Request $request): JsonResponse $user = User::where('email', $request->email)->first(); - if (!$user || !Hash::check($request->password, $user->password)) { + if (! $user || ! Hash::check($request->password, $user->password)) { return $this->sendError('Invalid credentials', [], 401); } @@ -42,7 +41,7 @@ public function login(Request $request): JsonResponse } catch (ValidationException $e) { return $this->sendValidationError($e->errors()); } catch (\Exception $e) { - return $this->sendError('Login failed: ' . $e->getMessage(), [], 500); + return $this->sendError('Login failed: '.$e->getMessage(), [], 500); } } @@ -78,7 +77,7 @@ public function register(Request $request): JsonResponse } catch (ValidationException $e) { return $this->sendValidationError($e->errors()); } catch (\Exception $e) { - return $this->sendError('Registration failed: ' . $e->getMessage(), [], 500); + return $this->sendError('Registration failed: '.$e->getMessage(), [], 500); } } @@ -92,7 +91,7 @@ public function logout(Request $request): JsonResponse return $this->sendResponse(null, 'Logged out successfully'); } catch (\Exception $e) { - return $this->sendError('Logout failed: ' . $e->getMessage(), [], 500); + return $this->sendError('Logout failed: '.$e->getMessage(), [], 500); } } @@ -109,4 +108,4 @@ public function me(Request $request): JsonResponse ], ], 'User retrieved successfully'); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Api/V1/FeedsController.php b/app/Http/Controllers/Api/V1/FeedsController.php index 37f8bf1..f7ff4f0 100644 --- a/app/Http/Controllers/Api/V1/FeedsController.php +++ b/app/Http/Controllers/Api/V1/FeedsController.php @@ -10,8 +10,8 @@ use Exception; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use InvalidArgumentException; use Illuminate\Validation\ValidationException; +use InvalidArgumentException; class FeedsController extends BaseController { @@ -21,7 +21,7 @@ class FeedsController extends BaseController public function index(Request $request): JsonResponse { $perPage = min($request->get('per_page', 15), 100); - + $feeds = Feed::with(['language']) ->withCount('articles') ->orderBy('is_active', 'desc') @@ -37,7 +37,7 @@ public function index(Request $request): JsonResponse 'total' => $feeds->total(), 'from' => $feeds->firstItem(), 'to' => $feeds->lastItem(), - ] + ], ], 'Feeds retrieved successfully.'); } @@ -64,7 +64,7 @@ public function store(StoreFeedRequest $request, CreateFeedAction $createFeedAct } catch (InvalidArgumentException $e) { return $this->sendError($e->getMessage(), [], 422); } catch (Exception $e) { - return $this->sendError('Failed to create feed: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to create feed: '.$e->getMessage(), [], 500); } } @@ -97,7 +97,7 @@ public function update(UpdateFeedRequest $request, Feed $feed): JsonResponse } catch (ValidationException $e) { return $this->sendValidationError($e->errors()); } catch (Exception $e) { - return $this->sendError('Failed to update feed: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to update feed: '.$e->getMessage(), [], 500); } } @@ -114,7 +114,7 @@ public function destroy(Feed $feed): JsonResponse 'Feed deleted successfully!' ); } catch (Exception $e) { - return $this->sendError('Failed to delete feed: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to delete feed: '.$e->getMessage(), [], 500); } } @@ -124,7 +124,7 @@ public function destroy(Feed $feed): JsonResponse public function toggle(Feed $feed): JsonResponse { try { - $newStatus = !$feed->is_active; + $newStatus = ! $feed->is_active; $feed->update(['is_active' => $newStatus]); $status = $newStatus ? 'activated' : 'deactivated'; @@ -134,7 +134,7 @@ public function toggle(Feed $feed): JsonResponse "Feed {$status} successfully!" ); } catch (Exception $e) { - return $this->sendError('Failed to toggle feed status: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to toggle feed status: '.$e->getMessage(), [], 500); } } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Api/V1/KeywordsController.php b/app/Http/Controllers/Api/V1/KeywordsController.php index e120b41..2fa08f9 100644 --- a/app/Http/Controllers/Api/V1/KeywordsController.php +++ b/app/Http/Controllers/Api/V1/KeywordsController.php @@ -62,7 +62,7 @@ public function store(Request $request, Feed $feed, PlatformChannel $channel): J } catch (ValidationException $e) { return $this->sendValidationError($e->errors()); } catch (\Exception $e) { - return $this->sendError('Failed to create keyword: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to create keyword: '.$e->getMessage(), [], 500); } } @@ -90,7 +90,7 @@ public function update(Request $request, Feed $feed, PlatformChannel $channel, K } catch (ValidationException $e) { return $this->sendValidationError($e->errors()); } catch (\Exception $e) { - return $this->sendError('Failed to update keyword: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to update keyword: '.$e->getMessage(), [], 500); } } @@ -112,7 +112,7 @@ public function destroy(Feed $feed, PlatformChannel $channel, Keyword $keyword): 'Keyword deleted successfully!' ); } catch (\Exception $e) { - return $this->sendError('Failed to delete keyword: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to delete keyword: '.$e->getMessage(), [], 500); } } @@ -127,7 +127,7 @@ public function toggle(Feed $feed, PlatformChannel $channel, Keyword $keyword): return $this->sendNotFound('Keyword not found for this route.'); } - $newStatus = !$keyword->is_active; + $newStatus = ! $keyword->is_active; $keyword->update(['is_active' => $newStatus]); $status = $newStatus ? 'activated' : 'deactivated'; @@ -137,7 +137,7 @@ public function toggle(Feed $feed, PlatformChannel $channel, Keyword $keyword): "Keyword {$status} successfully!" ); } catch (\Exception $e) { - return $this->sendError('Failed to toggle keyword status: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to toggle keyword status: '.$e->getMessage(), [], 500); } } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Api/V1/LogsController.php b/app/Http/Controllers/Api/V1/LogsController.php index 7f5867c..f8163d9 100644 --- a/app/Http/Controllers/Api/V1/LogsController.php +++ b/app/Http/Controllers/Api/V1/LogsController.php @@ -49,7 +49,7 @@ public function index(Request $request): JsonResponse ], ], 'Logs retrieved successfully.'); } catch (\Exception $e) { - return $this->sendError('Failed to retrieve logs: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to retrieve logs: '.$e->getMessage(), [], 500); } } } diff --git a/app/Http/Controllers/Api/V1/PlatformAccountsController.php b/app/Http/Controllers/Api/V1/PlatformAccountsController.php index 08b2ce3..6684e37 100644 --- a/app/Http/Controllers/Api/V1/PlatformAccountsController.php +++ b/app/Http/Controllers/Api/V1/PlatformAccountsController.php @@ -53,6 +53,7 @@ public function store(StorePlatformAccountRequest $request, CreatePlatformAccoun if (str_contains($e->getMessage(), 'Rate limited by')) { return $this->sendError($e->getMessage(), [], 429); } + return $this->sendError('Invalid username or password. Please check your credentials and try again.', [], 422); } catch (Exception $e) { return $this->sendError('Unable to connect to the Lemmy instance. Please check the URL and try again.', [], 422); @@ -97,7 +98,7 @@ public function update(Request $request, PlatformAccount $platformAccount): Json } catch (ValidationException $e) { return $this->sendValidationError($e->errors()); } catch (Exception $e) { - return $this->sendError('Failed to update platform account: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to update platform account: '.$e->getMessage(), [], 500); } } @@ -114,7 +115,7 @@ public function destroy(PlatformAccount $platformAccount): JsonResponse 'Platform account deleted successfully!' ); } catch (Exception $e) { - return $this->sendError('Failed to delete platform account: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to delete platform account: '.$e->getMessage(), [], 500); } } @@ -131,7 +132,7 @@ public function setActive(PlatformAccount $platformAccount): JsonResponse "Set {$platformAccount->username}@{$platformAccount->instance_url} as active for {$platformAccount->platform->value}!" ); } catch (Exception $e) { - return $this->sendError('Failed to set platform account as active: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to set platform account as active: '.$e->getMessage(), [], 500); } } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Api/V1/RoutingController.php b/app/Http/Controllers/Api/V1/RoutingController.php index 185f099..137ae63 100644 --- a/app/Http/Controllers/Api/V1/RoutingController.php +++ b/app/Http/Controllers/Api/V1/RoutingController.php @@ -52,7 +52,7 @@ public function store(StoreRouteRequest $request, CreateRouteAction $createRoute 201 ); } catch (Exception $e) { - return $this->sendError('Failed to create routing configuration: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to create routing configuration: '.$e->getMessage(), [], 500); } } @@ -62,11 +62,11 @@ public function store(StoreRouteRequest $request, CreateRouteAction $createRoute public function show(Feed $feed, PlatformChannel $channel): JsonResponse { $route = $this->findRoute($feed, $channel); - - if (!$route) { + + if (! $route) { return $this->sendNotFound('Routing configuration not found.'); } - + $route->load(['feed', 'platformChannel', 'keywords']); return $this->sendResponse( @@ -83,7 +83,7 @@ public function update(Request $request, Feed $feed, PlatformChannel $channel): try { $route = $this->findRoute($feed, $channel); - if (!$route) { + if (! $route) { return $this->sendNotFound('Routing configuration not found.'); } @@ -103,7 +103,7 @@ public function update(Request $request, Feed $feed, PlatformChannel $channel): } catch (ValidationException $e) { return $this->sendValidationError($e->errors()); } catch (Exception $e) { - return $this->sendError('Failed to update routing configuration: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to update routing configuration: '.$e->getMessage(), [], 500); } } @@ -115,7 +115,7 @@ public function destroy(Feed $feed, PlatformChannel $channel): JsonResponse try { $route = $this->findRoute($feed, $channel); - if (!$route) { + if (! $route) { return $this->sendNotFound('Routing configuration not found.'); } @@ -128,7 +128,7 @@ public function destroy(Feed $feed, PlatformChannel $channel): JsonResponse 'Routing configuration deleted successfully!' ); } catch (Exception $e) { - return $this->sendError('Failed to delete routing configuration: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to delete routing configuration: '.$e->getMessage(), [], 500); } } @@ -140,11 +140,11 @@ public function toggle(Feed $feed, PlatformChannel $channel): JsonResponse try { $route = $this->findRoute($feed, $channel); - if (!$route) { + if (! $route) { return $this->sendNotFound('Routing configuration not found.'); } - $newStatus = !$route->is_active; + $newStatus = ! $route->is_active; Route::where('feed_id', $feed->id) ->where('platform_channel_id', $channel->id) ->update(['is_active' => $newStatus]); @@ -156,7 +156,7 @@ public function toggle(Feed $feed, PlatformChannel $channel): JsonResponse "Routing configuration {$status} successfully!" ); } catch (Exception $e) { - return $this->sendError('Failed to toggle routing configuration status: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to toggle routing configuration status: '.$e->getMessage(), [], 500); } } @@ -169,4 +169,4 @@ private function findRoute(Feed $feed, PlatformChannel $channel): ?Route ->where('platform_channel_id', $channel->id) ->first(); } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Api/V1/SettingsController.php b/app/Http/Controllers/Api/V1/SettingsController.php index 80edb29..8dd4987 100644 --- a/app/Http/Controllers/Api/V1/SettingsController.php +++ b/app/Http/Controllers/Api/V1/SettingsController.php @@ -23,7 +23,7 @@ public function index(): JsonResponse return $this->sendResponse($settings, 'Settings retrieved successfully.'); } catch (\Exception $e) { - return $this->sendError('Failed to retrieve settings: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to retrieve settings: '.$e->getMessage(), [], 500); } } @@ -64,7 +64,7 @@ public function update(Request $request): JsonResponse } catch (ValidationException $e) { return $this->sendValidationError($e->errors()); } catch (\Exception $e) { - return $this->sendError('Failed to update settings: ' . $e->getMessage(), [], 500); + return $this->sendError('Failed to update settings: '.$e->getMessage(), [], 500); } } } diff --git a/app/Http/Middleware/EnsureOnboardingComplete.php b/app/Http/Middleware/EnsureOnboardingComplete.php index b57d117..4fe4e88 100644 --- a/app/Http/Middleware/EnsureOnboardingComplete.php +++ b/app/Http/Middleware/EnsureOnboardingComplete.php @@ -26,4 +26,4 @@ public function handle(Request $request, Closure $next): Response return $next($request); } -} \ No newline at end of file +} diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index 303786e..81c999c 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -39,4 +39,4 @@ public function share(Request $request): array // ]); } -} \ No newline at end of file +} diff --git a/app/Http/Middleware/RedirectIfOnboardingComplete.php b/app/Http/Middleware/RedirectIfOnboardingComplete.php index 190bd77..f7415b8 100644 --- a/app/Http/Middleware/RedirectIfOnboardingComplete.php +++ b/app/Http/Middleware/RedirectIfOnboardingComplete.php @@ -20,10 +20,10 @@ public function __construct( */ public function handle(Request $request, Closure $next): Response { - if (!$this->onboardingService->needsOnboarding()) { + if (! $this->onboardingService->needsOnboarding()) { return redirect()->route('dashboard'); } return $next($request); } -} \ No newline at end of file +} diff --git a/app/Http/Requests/StoreFeedRequest.php b/app/Http/Requests/StoreFeedRequest.php index ac2e533..dfc41bf 100644 --- a/app/Http/Requests/StoreFeedRequest.php +++ b/app/Http/Requests/StoreFeedRequest.php @@ -23,7 +23,7 @@ public function rules(): array 'provider' => "required|in:{$providers}", 'language_id' => 'required|exists:languages,id', 'description' => 'nullable|string', - 'is_active' => 'boolean' + 'is_active' => 'boolean', ]; } -} \ No newline at end of file +} diff --git a/app/Http/Requests/UpdateFeedRequest.php b/app/Http/Requests/UpdateFeedRequest.php index f6ad39c..891d68b 100644 --- a/app/Http/Requests/UpdateFeedRequest.php +++ b/app/Http/Requests/UpdateFeedRequest.php @@ -19,11 +19,11 @@ public function rules(): array { return [ 'name' => 'required|string|max:255', - 'url' => 'required|url|unique:feeds,url,' . ($this->route('feed') instanceof Feed ? (string)$this->route('feed')->id : (string)$this->route('feed')), + 'url' => 'required|url|unique:feeds,url,'.($this->route('feed') instanceof Feed ? (string) $this->route('feed')->id : (string) $this->route('feed')), 'type' => 'required|in:website,rss', 'language_id' => 'required|exists:languages,id', 'description' => 'nullable|string', - 'is_active' => 'boolean' + 'is_active' => 'boolean', ]; } -} \ No newline at end of file +} diff --git a/app/Jobs/ArticleDiscoveryForFeedJob.php b/app/Jobs/ArticleDiscoveryForFeedJob.php index db494a6..2c94b7c 100644 --- a/app/Jobs/ArticleDiscoveryForFeedJob.php +++ b/app/Jobs/ArticleDiscoveryForFeedJob.php @@ -25,7 +25,7 @@ public function handle(LogSaver $logSaver, ArticleFetcher $articleFetcher): void $logSaver->info('Starting feed article fetch', null, [ 'feed_id' => $this->feed->id, 'feed_name' => $this->feed->name, - 'feed_url' => $this->feed->url + 'feed_url' => $this->feed->url, ]); $articles = $articleFetcher->getArticlesFromFeed($this->feed); @@ -33,7 +33,7 @@ public function handle(LogSaver $logSaver, ArticleFetcher $articleFetcher): void $logSaver->info('Feed article fetch completed', null, [ 'feed_id' => $this->feed->id, 'feed_name' => $this->feed->name, - 'articles_count' => $articles->count() + 'articles_count' => $articles->count(), ]); $this->feed->update(['last_fetched_at' => now()]); @@ -42,7 +42,7 @@ public function handle(LogSaver $logSaver, ArticleFetcher $articleFetcher): void public static function dispatchForAllActiveFeeds(): void { $logSaver = app(LogSaver::class); - + Feed::where('is_active', true) ->get() ->each(function (Feed $feed, $index) use ($logSaver) { @@ -56,7 +56,7 @@ public static function dispatchForAllActiveFeeds(): void $logSaver->info('Dispatched feed discovery job', null, [ 'feed_id' => $feed->id, 'feed_name' => $feed->name, - 'delay_minutes' => $delayMinutes + 'delay_minutes' => $delayMinutes, ]); }); } diff --git a/app/Jobs/ArticleDiscoveryJob.php b/app/Jobs/ArticleDiscoveryJob.php index c89894e..ece1f70 100644 --- a/app/Jobs/ArticleDiscoveryJob.php +++ b/app/Jobs/ArticleDiscoveryJob.php @@ -18,7 +18,7 @@ public function __construct() public function handle(LogSaver $logSaver): void { - if (!Setting::isArticleProcessingEnabled()) { + if (! Setting::isArticleProcessingEnabled()) { $logSaver->info('Article processing is disabled. Article discovery skipped.'); return; diff --git a/app/Jobs/PublishNextArticleJob.php b/app/Jobs/PublishNextArticleJob.php index f62c857..83bb74f 100644 --- a/app/Jobs/PublishNextArticleJob.php +++ b/app/Jobs/PublishNextArticleJob.php @@ -12,7 +12,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Queue\Queueable; -class PublishNextArticleJob implements ShouldQueue, ShouldBeUnique +class PublishNextArticleJob implements ShouldBeUnique, ShouldQueue { use Queueable; @@ -28,6 +28,7 @@ public function __construct() /** * Execute the job. + * * @throws PublishException */ public function handle(ArticleFetcher $articleFetcher, ArticlePublishingService $publishingService): void @@ -56,7 +57,7 @@ public function handle(ArticleFetcher $articleFetcher, ArticlePublishingService 'article_id' => $article->id, 'title' => $article->title, 'url' => $article->url, - 'created_at' => $article->created_at + 'created_at' => $article->created_at, ]); // Fetch article data @@ -64,18 +65,18 @@ public function handle(ArticleFetcher $articleFetcher, ArticlePublishingService try { $publishingService->publishToRoutedChannels($article, $extractedData); - + logger()->info('Successfully published article', [ 'article_id' => $article->id, - 'title' => $article->title + 'title' => $article->title, ]); } catch (PublishException $e) { logger()->error('Failed to publish article', [ 'article_id' => $article->id, - 'error' => $e->getMessage() + 'error' => $e->getMessage(), ]); - + throw $e; } } -} \ No newline at end of file +} diff --git a/app/Jobs/SyncChannelPostsJob.php b/app/Jobs/SyncChannelPostsJob.php index 2f5bee6..3ded064 100644 --- a/app/Jobs/SyncChannelPostsJob.php +++ b/app/Jobs/SyncChannelPostsJob.php @@ -15,7 +15,7 @@ use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Facades\Cache; -class SyncChannelPostsJob implements ShouldQueue, ShouldBeUnique +class SyncChannelPostsJob implements ShouldBeUnique, ShouldQueue { use Queueable; @@ -28,7 +28,7 @@ public function __construct( public static function dispatchForAllActiveChannels(): void { $logSaver = app(LogSaver::class); - + PlatformChannel::with(['platformInstance', 'platformAccounts']) ->whereHas('platformInstance', fn ($query) => $query->where('platform', PlatformEnum::LEMMY)) ->whereHas('platformAccounts', fn ($query) => $query->where('platform_accounts.is_active', true)) @@ -78,7 +78,7 @@ private function syncLemmyChannelPosts(LogSaver $logSaver): void } catch (Exception $e) { $logSaver->error('Failed to sync channel posts', $this->channel, [ - 'error' => $e->getMessage() + 'error' => $e->getMessage(), ]); throw $e; @@ -97,13 +97,13 @@ private function getAuthToken(LemmyApiService $api, PlatformAccount $account): s return $cachedToken; } - if (!$account->username || !$account->password) { + if (! $account->username || ! $account->password) { throw new PlatformAuthException(PlatformEnum::LEMMY, 'Missing credentials for account'); } $token = $api->login($account->username, $account->password); - if (!$token) { + if (! $token) { throw new PlatformAuthException(PlatformEnum::LEMMY, 'Login failed for account'); } diff --git a/app/Listeners/LogExceptionToDatabase.php b/app/Listeners/LogExceptionToDatabase.php index 3ccfa07..599e251 100644 --- a/app/Listeners/LogExceptionToDatabase.php +++ b/app/Listeners/LogExceptionToDatabase.php @@ -5,14 +5,14 @@ use App\Events\ExceptionLogged; use App\Events\ExceptionOccurred; use App\Models\Log; + class LogExceptionToDatabase { - public function handle(ExceptionOccurred $event): void { // Truncate the message to prevent database errors - $message = strlen($event->message) > 255 - ? substr($event->message, 0, 252) . '...' + $message = strlen($event->message) > 255 + ? substr($event->message, 0, 252).'...' : $event->message; try { @@ -24,15 +24,15 @@ public function handle(ExceptionOccurred $event): void 'file' => $event->exception->getFile(), 'line' => $event->exception->getLine(), 'trace' => $event->exception->getTraceAsString(), - ...$event->context - ] + ...$event->context, + ], ]); ExceptionLogged::dispatch($log); } catch (\Exception $e) { // Prevent infinite recursion by not logging this exception // Optionally log to file or other non-database destination - error_log("Failed to log exception to database: " . $e->getMessage()); + error_log('Failed to log exception to database: '.$e->getMessage()); } } } diff --git a/app/Listeners/ValidateArticleListener.php b/app/Listeners/ValidateArticleListener.php index 3b1352c..d5fff5d 100644 --- a/app/Listeners/ValidateArticleListener.php +++ b/app/Listeners/ValidateArticleListener.php @@ -41,6 +41,7 @@ public function handle(NewArticleFetched $event): void 'article_id' => $article->id, 'error' => $e->getMessage(), ]); + return; } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index dbcab92..13f3fdf 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -14,9 +14,7 @@ class AppServiceProvider extends ServiceProvider { - public function register(): void - { - } + public function register(): void {} public function boot(): void { diff --git a/config/feed.php b/config/feed.php index 4ddb9ea..c6cc819 100644 --- a/config/feed.php +++ b/config/feed.php @@ -74,4 +74,4 @@ 'max_articles_per_fetch' => 50, 'article_retention_days' => 30, ], -]; \ No newline at end of file +]; diff --git a/config/languages.php b/config/languages.php index 6b63ce0..25aa231 100644 --- a/config/languages.php +++ b/config/languages.php @@ -61,4 +61,4 @@ */ 'default' => 'en', -]; \ No newline at end of file +]; diff --git a/database/factories/ArticlePublicationFactory.php b/database/factories/ArticlePublicationFactory.php index ed59ac4..4fdc624 100644 --- a/database/factories/ArticlePublicationFactory.php +++ b/database/factories/ArticlePublicationFactory.php @@ -2,8 +2,8 @@ namespace Database\Factories; -use App\Models\ArticlePublication; use App\Models\Article; +use App\Models\ArticlePublication; use App\Models\PlatformChannel; use Illuminate\Database\Eloquent\Factories\Factory; @@ -32,4 +32,4 @@ public function recentlyPublished(): static 'published_at' => $this->faker->dateTimeBetween('-1 day', 'now'), ]); } -} \ No newline at end of file +} diff --git a/database/factories/FeedFactory.php b/database/factories/FeedFactory.php index d07c3f0..06c903c 100644 --- a/database/factories/FeedFactory.php +++ b/database/factories/FeedFactory.php @@ -78,4 +78,4 @@ public function belga(): static 'url' => 'https://www.belganewsagency.eu/', ]); } -} \ No newline at end of file +} diff --git a/database/factories/KeywordFactory.php b/database/factories/KeywordFactory.php index 57e6f0b..db36fd1 100644 --- a/database/factories/KeywordFactory.php +++ b/database/factories/KeywordFactory.php @@ -48,4 +48,4 @@ public function inactive(): static 'is_active' => false, ]); } -} \ No newline at end of file +} diff --git a/database/factories/LanguageFactory.php b/database/factories/LanguageFactory.php index 3e03213..c5ea2bf 100644 --- a/database/factories/LanguageFactory.php +++ b/database/factories/LanguageFactory.php @@ -37,4 +37,4 @@ public function english(): static 'native_name' => 'English', ]); } -} \ No newline at end of file +} diff --git a/database/factories/PlatformAccountFactory.php b/database/factories/PlatformAccountFactory.php index 6c01c17..398fe86 100644 --- a/database/factories/PlatformAccountFactory.php +++ b/database/factories/PlatformAccountFactory.php @@ -17,7 +17,7 @@ public function definition(): array { return [ 'platform' => PlatformEnum::LEMMY, - 'instance_url' => 'https://lemmy.' . $this->faker->domainName(), + 'instance_url' => 'https://lemmy.'.$this->faker->domainName(), 'username' => $this->faker->userName(), 'password' => 'test-password', 'settings' => [], @@ -49,4 +49,4 @@ public function failed(): static 'status' => 'failed', ]); } -} \ No newline at end of file +} diff --git a/database/factories/PlatformChannelFactory.php b/database/factories/PlatformChannelFactory.php index 3643da2..e087cd7 100644 --- a/database/factories/PlatformChannelFactory.php +++ b/database/factories/PlatformChannelFactory.php @@ -34,14 +34,14 @@ public function inactive(): static ]); } - public function community(string $name = null): static + public function community(?string $name = null): static { $communityName = $name ?: $this->faker->word(); - + return $this->state(fn (array $attributes) => [ 'channel_id' => strtolower($communityName), 'name' => $communityName, 'display_name' => ucfirst($communityName), ]); } -} \ No newline at end of file +} diff --git a/database/factories/PlatformInstanceFactory.php b/database/factories/PlatformInstanceFactory.php index 182f9dc..956427d 100644 --- a/database/factories/PlatformInstanceFactory.php +++ b/database/factories/PlatformInstanceFactory.php @@ -33,8 +33,8 @@ public function lemmy(): static { return $this->state(fn (array $attributes) => [ 'platform' => 'lemmy', - 'name' => 'Lemmy ' . $this->faker->word(), - 'url' => 'https://lemmy.' . $this->faker->domainName(), + 'name' => 'Lemmy '.$this->faker->word(), + 'url' => 'https://lemmy.'.$this->faker->domainName(), ]); } -} \ No newline at end of file +} diff --git a/database/factories/RouteFactory.php b/database/factories/RouteFactory.php index 53177ac..93684f0 100644 --- a/database/factories/RouteFactory.php +++ b/database/factories/RouteFactory.php @@ -2,9 +2,9 @@ namespace Database\Factories; -use App\Models\Route; use App\Models\Feed; use App\Models\PlatformChannel; +use App\Models\Route; use Illuminate\Database\Eloquent\Factories\Factory; class RouteFactory extends Factory @@ -36,4 +36,4 @@ public function inactive(): static 'is_active' => false, ]); } -} \ No newline at end of file +} diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index a8aa2a6..9ac8fe0 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -32,4 +32,4 @@ public function withValue(string $value): static 'value' => $value, ]); } -} \ No newline at end of file +} diff --git a/database/migrations/2024_01_01_000002_create_languages.php b/database/migrations/2024_01_01_000002_create_languages.php index 0b55878..4e52a68 100644 --- a/database/migrations/2024_01_01_000002_create_languages.php +++ b/database/migrations/2024_01_01_000002_create_languages.php @@ -23,4 +23,4 @@ public function down(): void { Schema::dropIfExists('languages'); } -}; \ No newline at end of file +}; diff --git a/database/migrations/2024_01_01_000004_create_feeds_and_routes.php b/database/migrations/2024_01_01_000004_create_feeds_and_routes.php index 1bf820a..15099d8 100644 --- a/database/migrations/2024_01_01_000004_create_feeds_and_routes.php +++ b/database/migrations/2024_01_01_000004_create_feeds_and_routes.php @@ -60,4 +60,4 @@ public function down(): void Schema::dropIfExists('routes'); Schema::dropIfExists('feeds'); } -}; \ No newline at end of file +}; diff --git a/database/seeders/LanguageSeeder.php b/database/seeders/LanguageSeeder.php index 389d452..b967d88 100644 --- a/database/seeders/LanguageSeeder.php +++ b/database/seeders/LanguageSeeder.php @@ -21,4 +21,4 @@ public function run(): void ); } } -} \ No newline at end of file +} diff --git a/database/seeders/PlatformInstanceSeeder.php b/database/seeders/PlatformInstanceSeeder.php index 1b3e841..1d47848 100644 --- a/database/seeders/PlatformInstanceSeeder.php +++ b/database/seeders/PlatformInstanceSeeder.php @@ -17,14 +17,13 @@ public function run(): void 'name' => 'Belgae Social', 'description' => 'A Belgian Lemmy instance on the fediverse', ], - ])->each (fn ($instanceData) => - PlatformInstance::updateOrCreate( - [ - 'platform' => $instanceData['platform'], - 'url' => $instanceData['url'], - ], - $instanceData - ) + ])->each(fn ($instanceData) => PlatformInstance::updateOrCreate( + [ + 'platform' => $instanceData['platform'], + 'url' => $instanceData['url'], + ], + $instanceData + ) ); } -} \ No newline at end of file +} diff --git a/database/seeders/SettingsSeeder.php b/database/seeders/SettingsSeeder.php index 8f6b388..115153d 100644 --- a/database/seeders/SettingsSeeder.php +++ b/database/seeders/SettingsSeeder.php @@ -3,7 +3,6 @@ namespace Database\Seeders; use App\Models\Setting; -use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; class SettingsSeeder extends Seeder diff --git a/routes/api.php b/routes/api.php index 3142d04..7e12a04 100644 --- a/routes/api.php +++ b/routes/api.php @@ -4,12 +4,12 @@ use App\Http\Controllers\Api\V1\AuthController; use App\Http\Controllers\Api\V1\DashboardController; use App\Http\Controllers\Api\V1\FeedsController; +use App\Http\Controllers\Api\V1\KeywordsController; use App\Http\Controllers\Api\V1\LogsController; use App\Http\Controllers\Api\V1\OnboardingController; use App\Http\Controllers\Api\V1\PlatformAccountsController; use App\Http\Controllers\Api\V1\PlatformChannelsController; use App\Http\Controllers\Api\V1\RoutingController; -use App\Http\Controllers\Api\V1\KeywordsController; use App\Http\Controllers\Api\V1\SettingsController; use Illuminate\Support\Facades\Route;