StrStartsWithRector

pull/7361/head
Your Name 5 days ago
parent 9e052883bf
commit 4547b1fc11

@ -363,7 +363,7 @@ class LiveStreamController extends Controller
$key = $request->filled('name') ? $request->input('name') : $url['name'];
}
$token = substr($name, 0, 10) === 'streamkey-';
$token = str_starts_with($name, 'streamkey-');
if ($token) {
$stream = LiveStream::whereStreamKey($key)->firstOrFail();

@ -545,7 +545,7 @@ class RemoteAuthController extends Controller
]);
$account = $request->input('account');
abort_unless(substr(strtolower($account), 0, 8) === 'https://', 404);
abort_unless(str_starts_with(strtolower($account), 'https://'), 404);
$host = strtolower(config('pixelfed.domain.app'));
$domain = strtolower(parse_url($account, PHP_URL_HOST));

@ -52,7 +52,7 @@ class SpaController extends Controller
{
abort_unless(config('exp.spa'), 404);
if ($request->user()) {
if (substr($id, 0, 1) == '@') {
if (str_starts_with($id, '@')) {
$id = AccountService::usernameToId(substr($id, 1));
return redirect("/i/web/profile/{$id}");

@ -82,7 +82,7 @@ class StatusTagsPipeline implements ShouldQueue
return $tag && $tag['type'] == 'Hashtag' && isset($tag['href'], $tag['name']);
})
->map(function ($tag) use ($status) {
$name = substr($tag['name'], 0, 1) == '#' ?
$name = str_starts_with($tag['name'], '#') ?
substr($tag['name'], 1) : $tag['name'];
$banned = TrendingHashtagService::getBannedHashtagNames();
@ -143,7 +143,7 @@ class StatusTagsPipeline implements ShouldQueue
return $tag &&
$tag['type'] == 'Mention' &&
isset($tag['href']) &&
substr($tag['href'], 0, 8) === 'https://';
str_starts_with($tag['href'], 'https://');
})
->map(function ($tag) use ($status) {
if (Helpers::validateLocalUrl($tag['href'])) {

@ -201,7 +201,7 @@ class Profile extends Model
}
if ($avatar->cdn_url) {
if (substr($avatar->cdn_url, 0, 8) === 'https://') {
if (str_starts_with($avatar->cdn_url, 'https://')) {
return $avatar->cdn_url;
}
@ -225,7 +225,7 @@ class Profile extends Model
return url('/storage/avatars/default.jpg');
}
if (substr($path, 0, 6) !== 'public') {
if (!str_starts_with($path, 'public')) {
return url('/storage/avatars/default.jpg');
}

@ -84,10 +84,10 @@ class SearchApiV2Service
$rawQuery = $initalQuery ? $initalQuery : $this->query->input('q');
$query = $rawQuery.'%';
$webfingerQuery = $query;
if (Str::substrCount($rawQuery, '@') == 1 && substr($rawQuery, 0, 1) !== '@') {
if (Str::substrCount($rawQuery, '@') == 1 && !str_starts_with($rawQuery, '@')) {
$query = '@'.$query;
}
if (substr($webfingerQuery, 0, 1) !== '@') {
if (!str_starts_with($webfingerQuery, '@')) {
$webfingerQuery = '@'.$webfingerQuery;
}
$banned = InstanceService::getBannedDomains() ?? [];
@ -222,7 +222,7 @@ class SearchApiV2Service
)
);
}
if (substr($query, 0, 1) === '@' && ! Str::contains($query, '.')) {
if (str_starts_with($query, '@') && ! Str::contains($query, '.')) {
$default['accounts'] = $this->accounts(substr($query, 1));
return $default;
@ -244,7 +244,7 @@ class SearchApiV2Service
! Str::startsWith($query, 'http') &&
Str::substrCount($query, '@') == 1 &&
str_contains($query, '@') &&
strpos($query, '@') !== 0
!str_starts_with($query, '@')
) {
try {
$res = WebfingerService::lookup('@'.$query, $mastodonMode);

Loading…
Cancel
Save