Set up PHPStan

This commit is contained in:
myrmidex 2025-07-06 10:53:37 +02:00
parent e6f9c2eea8
commit ad572148f0
4 changed files with 26 additions and 14 deletions

View file

@ -63,11 +63,11 @@ private function syncLemmyChannelPosts(): void
$token = $this->getAuthToken($api, $account);
// Get community ID from channel_id or resolve from name
$communityId = $this->channel->channel_id
$platformChannelId = $this->channel->channel_id
? (int) $this->channel->channel_id
: $api->getCommunityId($this->channel->name);
: $api->getCommunityId($this->channel->name, $token);
$api->syncChannelPosts($token, $communityId, $this->channel->name);
$api->syncChannelPosts($token, $platformChannelId, $this->channel->name);
LogSaver::info('Channel posts synced successfully', $this->channel);

View file

@ -5,7 +5,6 @@
use App\Enums\PlatformEnum;
use App\Models\PlatformChannelPost;
use App\Modules\Lemmy\LemmyRequest;
use App\Services\Auth\LemmyAuthService;
use Exception;
class LemmyApiService
@ -42,10 +41,9 @@ public function login(string $username, string $password): ?string
}
}
public function getCommunityId(string $communityName): int
public function getCommunityId(string $communityName, string $token): int
{
try {
$token = LemmyAuthService::getToken();
$request = new LemmyRequest($this->instance, $token);
$response = $request->get('community', ['name' => $communityName]);
@ -61,12 +59,12 @@ public function getCommunityId(string $communityName): int
}
}
public function syncChannelPosts(string $token, int $communityId, string $communityName): void
public function syncChannelPosts(string $token, int $platformChannelId, string $communityName): void
{
try {
$request = new LemmyRequest($this->instance, $token);
$response = $request->get('post/list', [
'community_id' => $communityId,
'community_id' => $platformChannelId,
'limit' => 50,
'sort' => 'New'
]);
@ -74,7 +72,7 @@ public function syncChannelPosts(string $token, int $communityId, string $commun
if (!$response->successful()) {
logger()->warning('Failed to sync channel posts', [
'status' => $response->status(),
'community_id' => $communityId
'platform_channel_id' => $platformChannelId
]);
return;
}
@ -87,7 +85,7 @@ public function syncChannelPosts(string $token, int $communityId, string $commun
PlatformChannelPost::storePost(
PlatformEnum::LEMMY,
(string) $communityId,
(string) $platformChannelId,
$communityName,
(string) $post['id'],
$post['url'] ?? null,
@ -97,19 +95,19 @@ public function syncChannelPosts(string $token, int $communityId, string $commun
}
logger()->info('Synced channel posts', [
'community_id' => $communityId,
'platform_channel_id' => $platformChannelId,
'posts_count' => count($posts)
]);
} catch (Exception $e) {
logger()->error('Exception while syncing channel posts', [
'error' => $e->getMessage(),
'community_id' => $communityId
'platform_channel_id' => $platformChannelId
]);
}
}
public function createPost(string $token, string $title, string $body, int $communityId, ?string $url = null, ?string $thumbnail = null, ?int $languageId = null): array
public function createPost(string $token, string $title, string $body, int $platformChannelId, ?string $url = null, ?string $thumbnail = null, ?int $languageId = null): array
{
try {
$request = new LemmyRequest($this->instance, $token);
@ -117,7 +115,7 @@ public function createPost(string $token, string $title, string $body, int $comm
$postData = [
'name' => $title,
'body' => $body,
'community_id' => $communityId,
'community_id' => $platformChannelId,
];
if ($url) {

View file

@ -19,11 +19,13 @@
},
"require-dev": {
"fakerphp/faker": "^1.23",
"larastan/larastan": "^3.5",
"laravel/pail": "^1.2.2",
"laravel/pint": "^1.18",
"laravel/sail": "^1.43",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^11.5.3"
},
"autoload": {

12
phpstan.neon Normal file
View file

@ -0,0 +1,12 @@
includes:
- vendor/larastan/larastan/extension.neon
parameters:
level: 0
paths:
- app/
- tests/
excludePaths:
- bootstrap/*.php
- storage/*