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 <noreply@anthropic.com>
pull/7192/head
Your Name 2 weeks ago
parent 2df104c309
commit a424493420

@ -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);

@ -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'),

@ -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 [];

@ -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 [];
}

@ -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'),

@ -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];

@ -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);

@ -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();

@ -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')

@ -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'),

@ -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);

@ -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);

@ -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}";
}
}

@ -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=')) {

@ -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));
}
/**

@ -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;
}
}

Loading…
Cancel
Save