From a4244934203bae935df2119284ebc8a520662b10 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 11 Sep 2026 21:38:22 +0930 Subject: [PATCH] Replace Str::of() fluent chains with static Str::/native calls Aligns with the app's dominant convention (171 static Str:: calls vs 24 Str::of() chains). Uses Str::afterLast() for the repeated "segment after last slash" pattern, Str::matchAll() where a Collection return is needed, and native explode()/substr() where a plain array/string suffices. Co-Authored-By: Claude Sonnet 5 --- app/Console/Commands/FixBugs/AvatarStorage.php | 2 +- app/Http/Controllers/Admin/AdminDirectoryController.php | 4 ++-- app/Http/Controllers/ComposeController.php | 4 ++-- app/Http/Controllers/DirectMessageController.php | 4 ++-- app/Http/Controllers/PixelfedDirectoryController.php | 3 +-- app/Http/Controllers/RemoteAuthController.php | 2 +- app/Jobs/AvatarPipeline/AvatarStorageLargePurge.php | 2 +- app/Models/CustomEmoji.php | 3 +-- app/Services/AccountService.php | 3 +-- app/Services/AdminSettingsService.php | 8 ++++---- app/Services/AvatarService.php | 2 +- app/Util/ActivityPub/Inbox/HandlesStories.php | 4 ++-- app/Util/Lexer/Autolink.php | 2 +- app/Util/Lexer/Bearcap.php | 2 +- app/Util/Lexer/Classifier.php | 4 +--- app/Util/Lexer/Nickname.php | 4 ++-- 16 files changed, 24 insertions(+), 29 deletions(-) diff --git a/app/Console/Commands/FixBugs/AvatarStorage.php b/app/Console/Commands/FixBugs/AvatarStorage.php index 636c126fe..3b66e1dc4 100644 --- a/app/Console/Commands/FixBugs/AvatarStorage.php +++ b/app/Console/Commands/FixBugs/AvatarStorage.php @@ -185,7 +185,7 @@ class AvatarStorage extends Command $avatar->cdn_url = $disk->url('cache/avatars/default.jpg'); $avatar->save(); } else { - if (! $avatar->media_path || ! Str::of($avatar->media_path)->startsWith('public/avatars/')) { + if (! $avatar->media_path || ! Str::startsWith($avatar->media_path, 'public/avatars/')) { continue; } $ext = pathinfo($avatar->media_path, PATHINFO_EXTENSION); diff --git a/app/Http/Controllers/Admin/AdminDirectoryController.php b/app/Http/Controllers/Admin/AdminDirectoryController.php index 7d672f724..f5f1bd847 100644 --- a/app/Http/Controllers/Admin/AdminDirectoryController.php +++ b/app/Http/Controllers/Admin/AdminDirectoryController.php @@ -74,7 +74,7 @@ trait AdminDirectoryController $res['activitypub_enabled'] = (bool) config_cache('federation.activitypub.enabled'); $res['feature_config'] = [ - 'media_types' => Str::of(config_cache('pixelfed.media_types'))->explode(','), + 'media_types' => explode(',', config_cache('pixelfed.media_types')), 'image_quality' => config_cache('pixelfed.image_quality'), 'optimize_image' => (bool) config_cache('pixelfed.optimize_image'), 'max_photo_size' => config_cache('pixelfed.max_photo_size'), @@ -249,7 +249,7 @@ trait AdminDirectoryController 'curated_onboarding' => (bool) config_cache('instance.curated_registration.enabled'), 'activitypub_enabled' => config_cache('federation.activitypub.enabled'), 'oauth_enabled' => (bool) config_cache('pixelfed.oauth_enabled'), - 'media_types' => Str::of(config_cache('pixelfed.media_types'))->explode(','), + 'media_types' => explode(',', config_cache('pixelfed.media_types')), 'image_quality' => config_cache('pixelfed.image_quality'), 'optimize_image' => config_cache('pixelfed.optimize_image'), 'max_photo_size' => config_cache('pixelfed.max_photo_size'), diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index 4a129277b..2cf59daa2 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -252,7 +252,7 @@ class ComposeController extends Controller $q = $request->input('q'); - $cleanQuery = Str::of($q)->startsWith('@') ? Str::substr($q, 1) : $q; + $cleanQuery = Str::startsWith($q, '@') ? Str::substr($q, 1) : $q; if (strlen($cleanQuery) < 2) { return []; @@ -444,7 +444,7 @@ class ComposeController extends Controller $q = $request->input('q'); - $cleanQuery = Str::of($q)->startsWith('@') ? Str::substr($q, 1) : $q; + $cleanQuery = Str::startsWith($q, '@') ? Str::substr($q, 1) : $q; if (strlen($cleanQuery) < 2) { return []; diff --git a/app/Http/Controllers/DirectMessageController.php b/app/Http/Controllers/DirectMessageController.php index ba7fc530e..22b0a2cfb 100644 --- a/app/Http/Controllers/DirectMessageController.php +++ b/app/Http/Controllers/DirectMessageController.php @@ -555,7 +555,7 @@ class DirectMessageController extends Controller $q = $request->input('q'); $r = $request->input('remote', false); - if ($r && ! Str::of($q)->contains('.')) { + if ($r && ! Str::contains($q, '.')) { return []; } @@ -563,7 +563,7 @@ class DirectMessageController extends Controller Helpers::profileFetch($q); } - if (Str::of($q)->startsWith('@')) { + if (Str::startsWith($q, '@')) { if (strlen($q) < 3) { return []; } diff --git a/app/Http/Controllers/PixelfedDirectoryController.php b/app/Http/Controllers/PixelfedDirectoryController.php index ad37541cc..ee2b8008b 100644 --- a/app/Http/Controllers/PixelfedDirectoryController.php +++ b/app/Http/Controllers/PixelfedDirectoryController.php @@ -11,7 +11,6 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Str; class PixelfedDirectoryController extends Controller { @@ -99,7 +98,7 @@ class PixelfedDirectoryController extends Controller $res['activitypub_enabled'] = (bool) config_cache('federation.activitypub.enabled'); $res['feature_config'] = [ - 'media_types' => Str::of(config_cache('pixelfed.media_types'))->explode(','), + 'media_types' => explode(',', config_cache('pixelfed.media_types')), 'image_quality' => config_cache('pixelfed.image_quality'), 'optimize_image' => (bool) config_cache('pixelfed.optimize_image'), 'max_photo_size' => config_cache('pixelfed.max_photo_size'), diff --git a/app/Http/Controllers/RemoteAuthController.php b/app/Http/Controllers/RemoteAuthController.php index 00bfa397a..7a01aecde 100644 --- a/app/Http/Controllers/RemoteAuthController.php +++ b/app/Http/Controllers/RemoteAuthController.php @@ -551,7 +551,7 @@ class RemoteAuthController extends Controller $domain = strtolower(parse_url($account, PHP_URL_HOST)); if ($domain == $host) { - $username = Str::of($account)->explode('/')->last(); + $username = Str::afterLast($account, '/'); $user = User::where('username', $username)->first(); if ($user) { return ['id' => (string) $user->profile_id]; diff --git a/app/Jobs/AvatarPipeline/AvatarStorageLargePurge.php b/app/Jobs/AvatarPipeline/AvatarStorageLargePurge.php index a39bad1f1..03a4251ca 100644 --- a/app/Jobs/AvatarPipeline/AvatarStorageLargePurge.php +++ b/app/Jobs/AvatarPipeline/AvatarStorageLargePurge.php @@ -71,7 +71,7 @@ class AvatarStorageLargePurge implements ShouldBeUniqueUntilProcessing, ShouldQu $files = collect(AvatarService::storage($avatar)); - $curFile = Str::of($avatar->cdn_url)->explode('/')->last(); + $curFile = Str::afterLast($avatar->cdn_url, '/'); $files = $files->filter(function ($f) use ($curFile) { return ! $curFile || ! str_ends_with($f, $curFile); diff --git a/app/Models/CustomEmoji.php b/app/Models/CustomEmoji.php index 54df93792..fed510273 100644 --- a/app/Models/CustomEmoji.php +++ b/app/Models/CustomEmoji.php @@ -31,8 +31,7 @@ class CustomEmoji extends Model return []; } - return Str::of($text) - ->matchAll(self::SCAN_RE) + return Str::matchAll(self::SCAN_RE, $text) ->map(function ($match) use ($activitypub) { $tag = Cache::remember(self::CACHE_KEY.$match, 14400, function () use ($match) { $emoji = self::orderBy('id')->whereDisabled(false)->whereShortcode(':'.$match.':')->first(); diff --git a/app/Services/AccountService.php b/app/Services/AccountService.php index f737a8a5c..d8dce3267 100644 --- a/app/Services/AccountService.php +++ b/app/Services/AccountService.php @@ -223,8 +223,7 @@ class AccountService $key = self::CACHE_KEY.'u2id:'.hash('sha256', $username); return Cache::remember($key, 14400, function () use ($username) { - $s = Str::of($username); - if ($s->contains('@') && ! $s->startsWith('@')) { + if (Str::contains($username, '@') && ! Str::startsWith($username, '@')) { $username = "@{$username}"; } $profile = DB::table('profiles') diff --git a/app/Services/AdminSettingsService.php b/app/Services/AdminSettingsService.php index 3cbaded59..f145f19ac 100644 --- a/app/Services/AdminSettingsService.php +++ b/app/Services/AdminSettingsService.php @@ -133,8 +133,8 @@ class AdminSettingsService 'captcha_enabled' => (bool) config_cache('captcha.enabled'), 'captcha_on_login' => (bool) config_cache('captcha.active.login'), 'captcha_on_register' => (bool) config_cache('captcha.active.register'), - 'captcha_secret' => Str::of(config_cache('captcha.secret'))->mask('*', 4, -4), - 'captcha_sitekey' => Str::of(config_cache('captcha.sitekey'))->mask('*', 4, -4), + 'captcha_secret' => Str::mask(config_cache('captcha.secret'), '*', 4, -4), + 'captcha_sitekey' => Str::mask(config_cache('captcha.sitekey'), '*', 4, -4), 'custom_emoji_enabled' => (bool) config_cache('federation.custom_emoji.enabled'), ]; } @@ -148,8 +148,8 @@ class AdminSettingsService $pkey = 'filesystems.disks.'.$cloud_disk.'.'; $disk = [ 'driver' => $cloud_disk, - 'key' => Str::of(config_cache($pkey.'key'))->mask('*', 0, -2), - 'secret' => Str::of(config_cache($pkey.'secret'))->mask('*', 0, -2), + 'key' => Str::mask(config_cache($pkey.'key'), '*', 0, -2), + 'secret' => Str::mask(config_cache($pkey.'secret'), '*', 0, -2), 'region' => config_cache($pkey.'region'), 'bucket' => config_cache($pkey.'bucket'), 'visibility' => config_cache($pkey.'visibility'), diff --git a/app/Services/AvatarService.php b/app/Services/AvatarService.php index ead0bfbdc..f070dc68c 100644 --- a/app/Services/AvatarService.php +++ b/app/Services/AvatarService.php @@ -117,7 +117,7 @@ class AvatarService return; } - $curFile = Str::of($avatar->cdn_url)->explode('/')->last(); + $curFile = Str::afterLast($avatar->cdn_url, '/'); $files = $files->filter(function ($f) use ($curFile) { return ! $curFile || ! str_ends_with($f, $curFile); diff --git a/app/Util/ActivityPub/Inbox/HandlesStories.php b/app/Util/ActivityPub/Inbox/HandlesStories.php index d93fb2ce5..d437b4ed7 100644 --- a/app/Util/ActivityPub/Inbox/HandlesStories.php +++ b/app/Util/ActivityPub/Inbox/HandlesStories.php @@ -66,7 +66,7 @@ trait HandlesStories } $profile = Helpers::profileFetch($actor); - $storyId = Str::of($obj['object'])->explode('/')->last(); + $storyId = Str::afterLast($obj['object'], '/'); $story = Story::whereActive(true) ->whereLocal(true) @@ -146,7 +146,7 @@ trait HandlesStories return; } - $storyId = Str::of($storyUrl)->explode('/')->last(); + $storyId = Str::afterLast($storyUrl, '/'); $targetProfile = Helpers::profileFetch($to); $story = Story::whereProfileId($targetProfile->id)->find($storyId); diff --git a/app/Util/Lexer/Autolink.php b/app/Util/Lexer/Autolink.php index 1a06da535..f16b61e26 100755 --- a/app/Util/Lexer/Autolink.php +++ b/app/Util/Lexer/Autolink.php @@ -738,7 +738,7 @@ class Autolink extends Regex if ($this->autolinkActiveUsersOnly == true) { if (! AutolinkService::mentionedUsernameExists($screen_name)) { - return Str::of($screen_name)->startsWith('@') ? $screen_name : "@{$screen_name}"; + return Str::startsWith($screen_name, '@') ? $screen_name : "@{$screen_name}"; } } diff --git a/app/Util/Lexer/Bearcap.php b/app/Util/Lexer/Bearcap.php index 97891e3f9..1fe318a6a 100644 --- a/app/Util/Lexer/Bearcap.php +++ b/app/Util/Lexer/Bearcap.php @@ -25,7 +25,7 @@ class Bearcap $res = []; - $parts = Str::of($str)->substr(6)->explode('&')->toArray(); + $parts = explode('&', Str::substr($str, 6)); foreach ($parts as $part) { if (Str::startsWith($part, 't=')) { diff --git a/app/Util/Lexer/Classifier.php b/app/Util/Lexer/Classifier.php index e941ae655..7f9b3b623 100644 --- a/app/Util/Lexer/Classifier.php +++ b/app/Util/Lexer/Classifier.php @@ -44,9 +44,7 @@ class Classifier return collect($tokens); } - return Str::of($string) - ->lower() - ->matchAll('/[[:alpha:]]+/u'); + return Str::matchAll('/[[:alpha:]]+/u', Str::lower($string)); } /** diff --git a/app/Util/Lexer/Nickname.php b/app/Util/Lexer/Nickname.php index 8a9917204..38e522cc2 100644 --- a/app/Util/Lexer/Nickname.php +++ b/app/Util/Lexer/Nickname.php @@ -8,7 +8,7 @@ class Nickname { public static function normalizeProfileUrl($url) { - if (! Str::of($url)->contains('@')) { + if (! Str::contains($url, '@')) { return; } @@ -19,7 +19,7 @@ class Nickname if (Str::startsWith($url, '@')) { $url = substr($url, 1); - if (! Str::of($url)->contains('@')) { + if (! Str::contains($url, '@')) { return; } }