Merge pull request #1476 from Ribas160/replace_usage_of_strpos_with_php8_functions

Replace usage of strpos with str_starts_with etc.
This commit is contained in:
El RIDO 2025-01-04 08:18:04 +01:00 committed by GitHub
commit dc85a67a03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 1373 additions and 561 deletions

View file

@ -371,7 +371,7 @@ class GoogleCloudStorage extends AbstractData
try {
foreach ($this->_bucket->objects(array('prefix' => $prefix)) as $object) {
$candidate = substr($object->name(), strlen($prefix));
if (strpos($candidate, '/') === false) {
if (!str_contains($candidate, '/')) {
$pastes[] = $candidate;
}
}

View file

@ -462,7 +462,7 @@ class S3Storage extends AbstractData
try {
foreach ($this->_listAllObjects($prefix) as $object) {
$candidate = substr($object['Key'], strlen($prefix));
if (strpos($candidate, '/') === false) {
if (!str_contains($candidate, '/')) {
$pastes[] = $candidate;
}
}

View file

@ -130,7 +130,7 @@ class I18n
// encode any non-integer arguments and the message ID, if it doesn't contain a link
$argsCount = count($args);
for ($i = 0; $i < $argsCount; ++$i) {
if ($i > 0 ? !is_int($args[$i]) : strpos($args[0], '<a') === false) {
if ($i > 0 ? !is_int($args[$i]) : !str_contains($args[0], '<a')) {
$args[$i] = self::encode($args[$i]);
}
}

View file

@ -146,7 +146,7 @@ class Request
} elseif (array_key_exists('jsonld', $this->_params) && !empty($this->_params['jsonld'])) {
$this->_operation = 'jsonld';
} elseif (array_key_exists('link', $this->_params) && !empty($this->_params['link'])) {
if (strpos($this->getRequestUri(), '/shortenviayourls') !== false || array_key_exists('shortenviayourls', $this->_params)) {
if (str_contains($this->getRequestUri(), '/shortenviayourls') || array_key_exists('shortenviayourls', $this->_params)) {
$this->_operation = 'yourlsproxy';
}
}
@ -267,9 +267,9 @@ class Request
(array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) &&
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'JSONHttpRequest') ||
($hasAcceptHeader &&
strpos($acceptHeader, self::MIME_JSON) !== false &&
strpos($acceptHeader, self::MIME_HTML) === false &&
strpos($acceptHeader, self::MIME_XHTML) === false)
str_contains($acceptHeader, self::MIME_JSON) &&
!str_contains($acceptHeader, self::MIME_HTML) &&
!str_contains($acceptHeader, self::MIME_XHTML))
) {
return true;
}
@ -300,11 +300,11 @@ class Request
foreach ($mediaTypes as $acceptedQuality => $acceptedValues) {
foreach ($acceptedValues as $acceptedValue) {
if (
strpos($acceptedValue, self::MIME_HTML) === 0 ||
strpos($acceptedValue, self::MIME_XHTML) === 0
str_starts_with($acceptedValue, self::MIME_HTML) ||
str_starts_with($acceptedValue, self::MIME_XHTML)
) {
return false;
} elseif (strpos($acceptedValue, self::MIME_JSON) === 0) {
} elseif (str_starts_with($acceptedValue, self::MIME_JSON)) {
return true;
}
}

View file

@ -47,7 +47,7 @@ class YourlsProxy
*/
public function __construct(Configuration $conf, $link)
{
if (strpos($link, $conf->getKey('basepath') . '?') !== 0) {
if (!str_starts_with($link, $conf->getKey('basepath') . '?')) {
$this->_error = 'Trying to shorten a URL that isn\'t pointing at our instance.';
return;
}