Browse Source

fix(CS): Migrate more strpos() calls to str_* functions

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/11190/head
Joas Schilling 2 years ago
parent
commit
592916c735
No known key found for this signature in database GPG Key ID: 74434EFE0D2E2205
  1. 12
      lib/Config.php
  2. 4
      lib/Controller/SignalingController.php
  3. 2
      lib/Deck/DeckPluginLoader.php
  4. 2
      lib/Flow/Operation.php
  5. 2
      lib/Maps/MapsPluginLoader.php
  6. 2
      lib/Migration/FixNamespaceInDatabaseTables.php
  7. 4
      lib/Recording/BackendNotifier.php
  8. 2
      lib/Room.php
  9. 4
      lib/Search/ConversationSearch.php
  10. 2
      lib/Search/MessageSearch.php
  11. 6
      lib/Service/CommandService.php
  12. 6
      lib/Settings/Admin/AdminSettings.php
  13. 4
      lib/Signaling/BackendNotifier.php

12
lib/Config.php

@ -295,19 +295,19 @@ class Config {
protected function getWebSocketDomainForSignalingServer(string $url): string {
$url .= '/';
if (strpos($url, 'https://') === 0) {
if (str_starts_with($url, 'https://')) {
return 'wss://' . substr($url, 8, strpos($url, '/', 9) - 8);
}
if (strpos($url, 'http://') === 0) {
if (str_starts_with($url, 'http://')) {
return 'ws://' . substr($url, 7, strpos($url, '/', 8) - 7);
}
if (strpos($url, 'wss://') === 0) {
if (str_starts_with($url, 'wss://')) {
return substr($url, 0, strpos($url, '/', 7));
}
if (strpos($url, 'ws://') === 0) {
if (str_starts_with($url, 'ws://')) {
return substr($url, 0, strpos($url, '/', 6));
}
@ -509,7 +509,7 @@ class Config {
return;
}
if (substr($alg, 0, 2) === 'ES') {
if (str_starts_with($alg, 'ES')) {
$privKey = openssl_pkey_new([
'curve_name' => 'prime256v1',
'private_key_bits' => 2048,
@ -520,7 +520,7 @@ class Config {
if (!openssl_pkey_export($privKey, $secret)) {
throw new \Exception('Could not export private key');
}
} elseif (substr($alg, 0, 2) === 'RS') {
} elseif (str_starts_with($alg, 'RS')) {
$privKey = openssl_pkey_new([
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,

4
lib/Controller/SignalingController.php

@ -235,11 +235,11 @@ class SignalingController extends OCSController {
$url = rtrim($signalingServers[$serverId]['server'], '/');
$url = strtolower($url);
if (strpos($url, 'wss://') === 0) {
if (str_starts_with($url, 'wss://')) {
$url = 'https://' . substr($url, 6);
}
if (strpos($url, 'ws://') === 0) {
if (str_starts_with($url, 'ws://')) {
$url = 'http://' . substr($url, 5);
}

2
lib/Deck/DeckPluginLoader.php

@ -48,7 +48,7 @@ class DeckPluginLoader implements IEventListener {
return;
}
if (strpos($this->request->getPathInfo(), '/apps/deck') === 0) {
if (str_starts_with($this->request->getPathInfo(), '/apps/deck')) {
Util::addScript('spreed', 'talk-collections');
Util::addScript('spreed', 'talk-deck');
}

2
lib/Flow/Operation.php

@ -159,7 +159,7 @@ class Operation implements IOperation {
case self::MESSAGE_MODES['ROOM_MENTION']:
return '@all ';
case self::MESSAGE_MODES['SELF_MENTION']:
$hasWhitespace = strpos($participant->getAttendee()->getActorId(), ' ') !== false;
$hasWhitespace = str_contains($participant->getAttendee()->getActorId(), ' ');
$enclosure = $hasWhitespace ? '"' : '';
return '@' . $enclosure . $participant->getAttendee()->getActorId() . $enclosure . ' ';
case self::MESSAGE_MODES['NO_MENTION']:

2
lib/Maps/MapsPluginLoader.php

@ -58,7 +58,7 @@ class MapsPluginLoader implements IEventListener {
return;
}
if (strpos($this->request->getPathInfo(), '/apps/maps') === 0) {
if (str_starts_with($this->request->getPathInfo(), '/apps/maps')) {
Util::addScript('spreed', 'talk-collections');
Util::addScript('spreed', 'talk-maps');
}

2
lib/Migration/FixNamespaceInDatabaseTables.php

@ -54,7 +54,7 @@ class FixNamespaceInDatabaseTables implements IRepairStep {
$result = $query->executeQuery();
while ($row = $result->fetch()) {
$oldClass = $row['class'];
if (strpos($oldClass, 'OCA\\Spreed\\') !== 0) {
if (!str_starts_with($oldClass, 'OCA\\Spreed\\')) {
continue;
}

4
lib/Recording/BackendNotifier.php

@ -103,9 +103,9 @@ class BackendNotifier {
$url = '/api/v1/room/' . $room->getToken();
$url = $recording['server'] . $url;
if (strpos($url, 'wss://') === 0) {
if (str_starts_with($url, 'wss://')) {
$url = 'https://' . substr($url, 6);
} elseif (strpos($url, 'ws://') === 0) {
} elseif (str_starts_with($url, 'ws://')) {
$url = 'http://' . substr($url, 5);
}
$body = json_encode($data);

2
lib/Room.php

@ -257,7 +257,7 @@ class Room {
/** @var RoomService $roomService */
$roomService = Server::get(RoomService::class);
$roomService->setName($this, json_encode($users), '');
} elseif (strpos($this->name, '["') !== 0) {
} elseif (!str_starts_with($this->name, '["')) {
// TODO use DI
$participantService = Server::get(ParticipantService::class);
// Not the json array, but the old fallback when someone left

4
lib/Search/ConversationSearch.php

@ -65,7 +65,7 @@ class ConversationSearch implements IProvider {
* @inheritDoc
*/
public function getOrder(string $route, array $routeParameters): int {
if (strpos($route, Application::APP_ID . '.') === 0) {
if (str_starts_with($route, Application::APP_ID . '.')) {
// Active app, prefer Talk results
return -1;
}
@ -88,7 +88,7 @@ class ConversationSearch implements IProvider {
$parameters = $query->getRouteParameters();
if (isset($parameters['token']) &&
$parameters['token'] === $room->getToken() &&
strpos($query->getRoute(), Application::APP_ID . '.') === 0) {
str_starts_with($query->getRoute(), Application::APP_ID . '.')) {
// Don't search the current conversation.
//User most likely looks for other things with the same name
continue;

2
lib/Search/MessageSearch.php

@ -76,7 +76,7 @@ class MessageSearch implements IProvider, IFilteringProvider {
* @inheritDoc
*/
public function getOrder(string $route, array $routeParameters): ?int {
if (strpos($route, Application::APP_ID . '.') === 0) {
if (str_starts_with($route, Application::APP_ID . '.')) {
// Active app, prefer Talk results
return -2;
}

6
lib/Service/CommandService.php

@ -127,7 +127,7 @@ class CommandService {
if ($command->getApp() === '' || $command->getApp() === null) {
$script = $command->getScript();
if (strpos($script, 'alias:') === 0) {
if (str_starts_with($script, 'alias:')) {
try {
$this->resolveAlias($command);
} catch (DoesNotExistException $e) {
@ -137,7 +137,7 @@ class CommandService {
if (preg_match('/[`\'"]{(?:ARGUMENTS|ROOM|USER)}[`\'"]/i', $script)) {
throw new \InvalidArgumentException('script-parameters', 6);
}
if (strpos($script, '{ARGUMENTS_DOUBLEQUOTE_ESCAPED}') !== false) {
if (str_contains($script, '{ARGUMENTS_DOUBLEQUOTE_ESCAPED}')) {
throw new \InvalidArgumentException('script-parameters', 6);
}
@ -165,7 +165,7 @@ class CommandService {
*/
public function resolveAlias(Command $command): Command {
$script = $command->getScript();
if (strpos($script, 'alias:') === 0) {
if (str_starts_with($script, 'alias:')) {
$alias = explode(':', $script, 3);
if (isset($alias[2])) {
[, $app, $cmd] = $alias;

6
lib/Settings/Admin/AdminSettings.php

@ -411,7 +411,7 @@ class AdminSettings implements ISettings {
}
$userLocale = $this->serverConfig->getUserValue($this->currentUser->getUID(), 'core', 'locale', 'en_US');
$guessCountry = 'US';
if (strpos($userLocale, '_') !== false) {
if (str_contains($userLocale, '_')) {
$guessCountry = substr($userLocale, strrpos($userLocale, '_') + 1);
$correctGuess = false;
foreach ($countries as $country) {
@ -519,11 +519,11 @@ class AdminSettings implements ISettings {
if ($usingFPM) {
// Needs to use mpm_event
return strpos($apacheModule, 'event') !== false ? '' : 'invalid';
return str_contains($apacheModule, 'event') ? '' : 'invalid';
}
// Needs to use mpm_prefork
return strpos($apacheModule, 'prefork') !== false ? '' : 'invalid';
return str_contains($apacheModule, 'prefork') ? '' : 'invalid';
}
/**

4
lib/Signaling/BackendNotifier.php

@ -122,9 +122,9 @@ class BackendNotifier {
$url = '/api/v1/room/' . $room->getToken();
$url = $signaling['server'] . $url;
if (strpos($url, 'wss://') === 0) {
if (str_starts_with($url, 'wss://')) {
$url = 'https://' . substr($url, 6);
} elseif (strpos($url, 'ws://') === 0) {
} elseif (str_starts_with($url, 'ws://')) {
$url = 'http://' . substr($url, 5);
}
$body = json_encode($data);

Loading…
Cancel
Save