Raise PHPStan level tp 5

This commit is contained in:
myrmidex 2025-07-06 20:52:58 +02:00
parent c851c2292c
commit 52ddf8c055
5 changed files with 19 additions and 11 deletions

View file

@ -8,6 +8,7 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\View as ViewFacade;
class PlatformAccountsController extends Controller class PlatformAccountsController extends Controller
{ {
@ -20,7 +21,7 @@ public function index(): View
public function create(): View public function create(): View
{ {
return view('pages.platforms.create'); return ViewFacade::make('pages.platforms.create');
} }
public function store(Request $request): RedirectResponse public function store(Request $request): RedirectResponse
@ -64,7 +65,7 @@ public function store(Request $request): RedirectResponse
public function edit(PlatformAccount $platformAccount): View 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 public function update(Request $request, PlatformAccount $platformAccount): RedirectResponse

View file

@ -7,6 +7,7 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\View as ViewFacade;
class PlatformChannelsController extends Controller class PlatformChannelsController extends Controller
{ {
@ -17,7 +18,7 @@ public function index(): View
->orderBy('name') ->orderBy('name')
->get(); ->get();
return view('pages.channels.index', compact('channels')); return ViewFacade::make('pages.channels.index', compact('channels'));
} }
public function create(): View public function create(): View
@ -26,7 +27,7 @@ public function create(): View
->orderBy('name') ->orderBy('name')
->get(); ->get();
return view('pages.channels.create', compact('instances')); return ViewFacade::make('pages.channels.create', compact('instances'));
} }
public function store(Request $request): RedirectResponse public function store(Request $request): RedirectResponse
@ -66,7 +67,7 @@ public function edit(PlatformChannel $channel): View
->orderBy('name') ->orderBy('name')
->get(); ->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 public function update(Request $request, PlatformChannel $channel): RedirectResponse

View file

@ -4,12 +4,14 @@
use App\Enums\PlatformEnum; use App\Enums\PlatformEnum;
use App\Exceptions\PlatformAuthException; use App\Exceptions\PlatformAuthException;
use App\Models\PlatformAccount;
use App\Models\PlatformChannel; use App\Models\PlatformChannel;
use App\Modules\Lemmy\Services\LemmyApiService; use App\Modules\Lemmy\Services\LemmyApiService;
use App\Services\Log\LogSaver; use App\Services\Log\LogSaver;
use Exception; use Exception;
use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Queue\Queueable; use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
@ -53,7 +55,9 @@ public function handle(): void
private function syncLemmyChannelPosts(): void private function syncLemmyChannelPosts(): void
{ {
try { try {
$account = $this->channel->platformAccounts()->where('is_active', true)->first(); /** @var Collection<int, PlatformAccount> $accounts */
$accounts = $this->channel->activePlatformAccounts()->get();
$account = $accounts->first();
if (! $account) { if (! $account) {
throw new PlatformAuthException(PlatformEnum::LEMMY, 'No active account found for channel'); throw new PlatformAuthException(PlatformEnum::LEMMY, 'No active account found for channel');
@ -62,9 +66,8 @@ private function syncLemmyChannelPosts(): void
$api = new LemmyApiService($this->channel->platformInstance->url); $api = new LemmyApiService($this->channel->platformInstance->url);
$token = $this->getAuthToken($api, $account); $token = $this->getAuthToken($api, $account);
// Get community ID from channel_id or resolve from name
$platformChannelId = $this->channel->channel_id $platformChannelId = $this->channel->channel_id
? (int) $this->channel->channel_id ? $this->channel->channel_id
: $api->getCommunityId($this->channel->name, $token); : $api->getCommunityId($this->channel->name, $token);
$api->syncChannelPosts($token, $platformChannelId, $this->channel->name); $api->syncChannelPosts($token, $platformChannelId, $this->channel->name);
@ -83,7 +86,7 @@ private function syncLemmyChannelPosts(): void
/** /**
* @throws PlatformAuthException * @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}"; $cacheKey = "lemmy_jwt_token_{$account->id}";
$cachedToken = Cache::get($cacheKey); $cachedToken = Cache::get($cacheKey);

View file

@ -10,6 +10,7 @@
use App\Modules\Lemmy\Services\LemmyPublisher; use App\Modules\Lemmy\Services\LemmyPublisher;
use App\Services\Log\LogSaver; use App\Services\Log\LogSaver;
use Exception; use Exception;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use RuntimeException; use RuntimeException;
@ -25,6 +26,8 @@ public function publishToRoutedChannels(Article $article, array $extractedData):
} }
$feed = $article->feed; $feed = $article->feed;
/** @var EloquentCollection<int, PlatformChannel> $activeChannels */
$activeChannels = $feed->activeChannels()->with(['platformInstance', 'activePlatformAccounts'])->get(); $activeChannels = $feed->activeChannels()->with(['platformInstance', 'activePlatformAccounts'])->get();
return $activeChannels->map(function (PlatformChannel $channel) use ($article, $extractedData) { return $activeChannels->map(function (PlatformChannel $channel) use ($article, $extractedData) {

View file

@ -2,7 +2,7 @@ includes:
- vendor/larastan/larastan/extension.neon - vendor/larastan/larastan/extension.neon
parameters: parameters:
level: 4 level: 5
paths: paths:
- app/ - app/
- tests/ - tests/