From 52ddf8c055593b3bf3eba8113051ff200f42b07b Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sun, 6 Jul 2025 20:52:58 +0200 Subject: [PATCH] Raise PHPStan level tp 5 --- app/Http/Controllers/PlatformAccountsController.php | 5 +++-- app/Http/Controllers/PlatformChannelsController.php | 7 ++++--- app/Jobs/SyncChannelPostsJob.php | 13 ++++++++----- .../Publishing/ArticlePublishingService.php | 3 +++ phpstan.neon | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/PlatformAccountsController.php b/app/Http/Controllers/PlatformAccountsController.php index 713b022..e96a57a 100644 --- a/app/Http/Controllers/PlatformAccountsController.php +++ b/app/Http/Controllers/PlatformAccountsController.php @@ -8,6 +8,7 @@ use Illuminate\Http\Request; use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\View as ViewFacade; class PlatformAccountsController extends Controller { @@ -20,7 +21,7 @@ public function index(): View public function create(): View { - return view('pages.platforms.create'); + return ViewFacade::make('pages.platforms.create'); } public function store(Request $request): RedirectResponse @@ -64,7 +65,7 @@ public function store(Request $request): RedirectResponse public function edit(PlatformAccount $platformAccount): View { - return view('pages.platforms.edit', compact('platformAccount')); + return ViewFacade::make('pages.platforms.edit', compact('platformAccount')); } public function update(Request $request, PlatformAccount $platformAccount): RedirectResponse diff --git a/app/Http/Controllers/PlatformChannelsController.php b/app/Http/Controllers/PlatformChannelsController.php index c3761cc..24c8772 100644 --- a/app/Http/Controllers/PlatformChannelsController.php +++ b/app/Http/Controllers/PlatformChannelsController.php @@ -7,6 +7,7 @@ use Illuminate\Http\Request; use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\View as ViewFacade; class PlatformChannelsController extends Controller { @@ -17,7 +18,7 @@ public function index(): View ->orderBy('name') ->get(); - return view('pages.channels.index', compact('channels')); + return ViewFacade::make('pages.channels.index', compact('channels')); } public function create(): View @@ -26,7 +27,7 @@ public function create(): View ->orderBy('name') ->get(); - return view('pages.channels.create', compact('instances')); + return ViewFacade::make('pages.channels.create', compact('instances')); } public function store(Request $request): RedirectResponse @@ -66,7 +67,7 @@ public function edit(PlatformChannel $channel): View ->orderBy('name') ->get(); - return view('pages.channels.edit', compact('channel', 'instances')); + return ViewFacade::make('pages.channels.edit', compact('channel', 'instances')); } public function update(Request $request, PlatformChannel $channel): RedirectResponse diff --git a/app/Jobs/SyncChannelPostsJob.php b/app/Jobs/SyncChannelPostsJob.php index 04098c6..7c8dcd3 100644 --- a/app/Jobs/SyncChannelPostsJob.php +++ b/app/Jobs/SyncChannelPostsJob.php @@ -4,12 +4,14 @@ use App\Enums\PlatformEnum; use App\Exceptions\PlatformAuthException; +use App\Models\PlatformAccount; use App\Models\PlatformChannel; use App\Modules\Lemmy\Services\LemmyApiService; use App\Services\Log\LogSaver; use Exception; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Facades\Cache; @@ -53,18 +55,19 @@ public function handle(): void private function syncLemmyChannelPosts(): void { try { - $account = $this->channel->platformAccounts()->where('is_active', true)->first(); + /** @var Collection $accounts */ + $accounts = $this->channel->activePlatformAccounts()->get(); + $account = $accounts->first(); - if (!$account) { + if (! $account) { throw new PlatformAuthException(PlatformEnum::LEMMY, 'No active account found for channel'); } $api = new LemmyApiService($this->channel->platformInstance->url); $token = $this->getAuthToken($api, $account); - // Get community ID from channel_id or resolve from name $platformChannelId = $this->channel->channel_id - ? (int) $this->channel->channel_id + ? $this->channel->channel_id : $api->getCommunityId($this->channel->name, $token); $api->syncChannelPosts($token, $platformChannelId, $this->channel->name); @@ -83,7 +86,7 @@ private function syncLemmyChannelPosts(): void /** * @throws PlatformAuthException */ - private function getAuthToken(LemmyApiService $api, \App\Models\PlatformAccount $account): string + private function getAuthToken(LemmyApiService $api, PlatformAccount $account): string { $cacheKey = "lemmy_jwt_token_{$account->id}"; $cachedToken = Cache::get($cacheKey); diff --git a/app/Services/Publishing/ArticlePublishingService.php b/app/Services/Publishing/ArticlePublishingService.php index a764466..db216e6 100644 --- a/app/Services/Publishing/ArticlePublishingService.php +++ b/app/Services/Publishing/ArticlePublishingService.php @@ -10,6 +10,7 @@ use App\Modules\Lemmy\Services\LemmyPublisher; use App\Services\Log\LogSaver; use Exception; +use Illuminate\Database\Eloquent\Collection as EloquentCollection; use Illuminate\Support\Collection; use RuntimeException; @@ -25,6 +26,8 @@ public function publishToRoutedChannels(Article $article, array $extractedData): } $feed = $article->feed; + + /** @var EloquentCollection $activeChannels */ $activeChannels = $feed->activeChannels()->with(['platformInstance', 'activePlatformAccounts'])->get(); return $activeChannels->map(function (PlatformChannel $channel) use ($article, $extractedData) { diff --git a/phpstan.neon b/phpstan.neon index c4bc952..d54bde2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,7 +2,7 @@ includes: - vendor/larastan/larastan/extension.neon parameters: - level: 4 + level: 5 paths: - app/ - tests/