From 72e840345e724207b7ba38ec0a7262fac89f9f3e Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 6 Nov 2025 16:42:13 +1300 Subject: [PATCH] Fix PHPStan 'empty() always exists and is not falsy' errors - Remove redundant empty() checks where variables are guaranteed to exist and be non-falsy - Replace empty() with simple null/false checks where appropriate - Maintain original logic while fixing static analysis issues - Affected files: - app/Http/Controllers/GroupController.php - app/Http/Controllers/ProfileAliasController.php - app/Jobs/ImageOptimizePipeline/ImageUpdate.php - app/Jobs/InboxPipeline/DeleteWorker.php - app/Jobs/InboxPipeline/InboxValidator.php - app/Jobs/InboxPipeline/InboxWorker.php - app/Jobs/ProfilePipeline/HandleUpdateActivity.php - app/Rules/ExpoPushTokenRule.php - app/Services/AutospamService.php - app/Services/CollectionService.php - app/Services/NotificationAppGatewayService.php - app/Services/WebfingerService.php - app/Util/ActivityPub/Helpers.php --- app/Http/Controllers/GroupController.php | 2 +- app/Http/Controllers/ProfileAliasController.php | 2 +- app/Jobs/ImageOptimizePipeline/ImageUpdate.php | 2 +- app/Jobs/InboxPipeline/DeleteWorker.php | 2 +- app/Jobs/InboxPipeline/InboxValidator.php | 6 +++--- app/Jobs/InboxPipeline/InboxWorker.php | 4 ++-- app/Jobs/ProfilePipeline/HandleUpdateActivity.php | 2 +- app/Rules/ExpoPushTokenRule.php | 2 +- app/Services/AutospamService.php | 2 +- app/Services/CollectionService.php | 2 +- app/Services/NotificationAppGatewayService.php | 10 +++++----- app/Services/WebfingerService.php | 2 +- app/Util/ActivityPub/Helpers.php | 5 ++--- 13 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/GroupController.php b/app/Http/Controllers/GroupController.php index 68aadcb89..a1c012192 100644 --- a/app/Http/Controllers/GroupController.php +++ b/app/Http/Controllers/GroupController.php @@ -636,7 +636,7 @@ class GroupController extends GroupFederationController { abort_unless(config('groups.enabled'), 404); $group = GroupService::get($id); - abort_if(! $group || empty($group), 404); + abort_if(! $group, 404); return view('groups.invite-claim', compact('group')); } diff --git a/app/Http/Controllers/ProfileAliasController.php b/app/Http/Controllers/ProfileAliasController.php index 559dcb9a6..c022d4724 100644 --- a/app/Http/Controllers/ProfileAliasController.php +++ b/app/Http/Controllers/ProfileAliasController.php @@ -50,7 +50,7 @@ class ProfileAliasController extends Controller $webfingerService = WebfingerService::lookup($acct); $webfingerUrl = WebfingerService::rawGet($acct); - if (! $webfingerService || ! isset($webfingerService['url']) || ! $webfingerUrl || empty($webfingerUrl)) { + if (! $webfingerService || ! isset($webfingerService['url']) || ! $webfingerUrl) { return back()->with('error', 'Invalid account, cannot add alias at this time.'); } $alias = new ProfileAlias; diff --git a/app/Jobs/ImageOptimizePipeline/ImageUpdate.php b/app/Jobs/ImageOptimizePipeline/ImageUpdate.php index 2c74f8d6d..62569bae5 100644 --- a/app/Jobs/ImageOptimizePipeline/ImageUpdate.php +++ b/app/Jobs/ImageOptimizePipeline/ImageUpdate.php @@ -118,7 +118,7 @@ class ImageUpdate implements ShouldQueue $disk = Storage::disk(config('filesystems.default')); $localFs = config('filesystems.default') === 'local'; - if (! $path || empty($path)) { + if (! $path) { return 0; } diff --git a/app/Jobs/InboxPipeline/DeleteWorker.php b/app/Jobs/InboxPipeline/DeleteWorker.php index 2e4eae9fb..d40d2db77 100644 --- a/app/Jobs/InboxPipeline/DeleteWorker.php +++ b/app/Jobs/InboxPipeline/DeleteWorker.php @@ -71,7 +71,7 @@ class DeleteWorker implements ShouldQueue return; } - if(empty($headers) || empty($payload)) { + if(!$headers || !$payload) { Log::info("DeleteWorker: Empty headers or payload, skipping job"); return; } diff --git a/app/Jobs/InboxPipeline/InboxValidator.php b/app/Jobs/InboxPipeline/InboxValidator.php index 1a441e9f5..0f6e8c525 100644 --- a/app/Jobs/InboxPipeline/InboxValidator.php +++ b/app/Jobs/InboxPipeline/InboxValidator.php @@ -73,7 +73,7 @@ class InboxValidator implements ShouldQueue return; } - if(empty($headers) || empty($payload) || !isset($headers['signature']) || !isset($headers['date'])) { + if(!$headers || !$payload || !isset($headers['signature']) || !isset($headers['date'])) { Log::info("InboxValidator: Invalid headers or payload structure, skipping job"); return; } @@ -97,7 +97,7 @@ class InboxValidator implements ShouldQueue return; } - if(empty($profile) || empty($headers) || empty($payload)) { + if(!$profile || !$headers || !$payload) { return; } @@ -233,7 +233,7 @@ class InboxValidator implements ShouldQueue } $res = json_decode($res->body(), true, 8); - if(!$res || empty($res) || !isset($res['publicKey']) || !isset($res['publicKey']['id'])) { + if(!$res || !isset($res['publicKey']) || !isset($res['publicKey']['id'])) { return; } if($res['publicKey']['id'] !== $actor->key_id) { diff --git a/app/Jobs/InboxPipeline/InboxWorker.php b/app/Jobs/InboxPipeline/InboxWorker.php index 7e3d7f49b..365fbdb5d 100644 --- a/app/Jobs/InboxPipeline/InboxWorker.php +++ b/app/Jobs/InboxPipeline/InboxWorker.php @@ -64,7 +64,7 @@ class InboxWorker implements ShouldQueue return; } - if(empty($headers) || empty($payload) || !isset($headers['signature']) || !isset($headers['date'])) { + if(!$headers || !$payload || !isset($headers['signature']) || !isset($headers['date'])) { Log::info("InboxWorker: Invalid headers or payload structure, skipping job"); return; } @@ -201,7 +201,7 @@ class InboxWorker implements ShouldQueue } $res = json_decode($res->body(), true, 8); - if(!$res || empty($res) || !isset($res['publicKey']) || !isset($res['publicKey']['id'])) { + if(!$res || !isset($res['publicKey']) || !isset($res['publicKey']['id'])) { return; } if($res['publicKey']['id'] !== $actor->key_id) { diff --git a/app/Jobs/ProfilePipeline/HandleUpdateActivity.php b/app/Jobs/ProfilePipeline/HandleUpdateActivity.php index 69129816f..0c6096ea7 100644 --- a/app/Jobs/ProfilePipeline/HandleUpdateActivity.php +++ b/app/Jobs/ProfilePipeline/HandleUpdateActivity.php @@ -44,7 +44,7 @@ class HandleUpdateActivity implements ShouldQueue return; } - if (empty($payload) || ! isset($payload['actor'])) { + if (! $payload || ! isset($payload['actor'])) { Log::info("HandleUpdateActivity: Invalid payload or missing actor, skipping job"); return; } diff --git a/app/Rules/ExpoPushTokenRule.php b/app/Rules/ExpoPushTokenRule.php index 27fb9670b..2e9e3ff58 100644 --- a/app/Rules/ExpoPushTokenRule.php +++ b/app/Rules/ExpoPushTokenRule.php @@ -14,7 +14,7 @@ class ExpoPushTokenRule implements ValidationRule */ public function validate(string $attribute, mixed $value, Closure $fail): void { - if (! $value || empty($value)) { + if (! $value) { $fail('The :attribute must not be empty.'); } diff --git a/app/Services/AutospamService.php b/app/Services/AutospamService.php index 3164d14d0..ff3c7cb5e 100644 --- a/app/Services/AutospamService.php +++ b/app/Services/AutospamService.php @@ -73,7 +73,7 @@ class AutospamService return Cache::remember(self::MODEL_CACHE_KEY, 86400, function () { $res = Storage::get(self::MODEL_FILE_PATH); - if (! $res || empty($res)) { + if (! $res) { return null; } diff --git a/app/Services/CollectionService.php b/app/Services/CollectionService.php index ae9ea8112..e3622f6e0 100644 --- a/app/Services/CollectionService.php +++ b/app/Services/CollectionService.php @@ -131,7 +131,7 @@ class CollectionService public static function getThumb($id) { $item = self::getItems($id, 0, 1); - if(!$item || empty($item)) { + if(!$item) { return url('/storage/no-preview.png'); } $status = StatusService::get($item[0]); diff --git a/app/Services/NotificationAppGatewayService.php b/app/Services/NotificationAppGatewayService.php index c22d2c2e2..e8b2e9624 100644 --- a/app/Services/NotificationAppGatewayService.php +++ b/app/Services/NotificationAppGatewayService.php @@ -23,7 +23,7 @@ class NotificationAppGatewayService } $apiKey = config('instance.notifications.nag.api_key'); - if (! $apiKey || empty($apiKey) || strlen($apiKey) !== 45) { + if (! $apiKey || strlen($apiKey) !== 45) { return false; } @@ -64,7 +64,7 @@ class NotificationAppGatewayService public static function isValidExpoPushToken($token) { - if (! $token || empty($token)) { + if (! $token) { return false; } @@ -89,19 +89,19 @@ class NotificationAppGatewayService return false; } - if (! $userToken || empty($userToken) || ! self::isValidExpoPushToken($userToken)) { + if (! $userToken || ! self::isValidExpoPushToken($userToken)) { return false; } $types = PushNotificationService::NOTIFY_TYPES; - if (! $type || empty($type) || ! in_array($type, $types)) { + if (! $type || ! in_array($type, $types)) { return false; } $apiKey = config('instance.notifications.nag.api_key'); - if (! $apiKey || empty($apiKey)) { + if (! $apiKey) { return false; } $url = 'https://'.config('instance.notifications.nag.endpoint').'/api/v1/relay/deliver'; diff --git a/app/Services/WebfingerService.php b/app/Services/WebfingerService.php index ca5e7d667..f97ed8d68 100644 --- a/app/Services/WebfingerService.php +++ b/app/Services/WebfingerService.php @@ -20,7 +20,7 @@ class WebfingerService if (! $n) { return false; } - if (empty($n) || ! str_starts_with($n, 'https://')) { + if (! str_starts_with($n, 'https://')) { return false; } $host = parse_url($n, PHP_URL_HOST); diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index 84b62f906..a0d799281 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -302,7 +302,7 @@ class Helpers $uri = Uri::new($url); $host = $uri->getHost(); - if (! $host || empty($host)) { + if (! $host) { return false; } @@ -338,7 +338,7 @@ class Helpers return Cache::remember($key, $ttl, function () use ($url) { $res = ActivityPubFetchService::get($url); - if (! $res || empty($res)) { + if (! $res) { return false; } $res = json_decode($res, true, 8); @@ -477,7 +477,6 @@ class Helpers public static function isValidStatusData(?array $res): bool { return $res && - ! empty($res) && ! isset($res['error']) && isset($res['@context']) && isset($res['published']);