Skip to content

Commit

Permalink
Merge pull request #39213 from shdehnavi/replace_strpos_and_substr_ca…
Browse files Browse the repository at this point in the history
…lls_in_federatedfilesharing_app

Refactor "strpos" and "substr" calls in federatedfilesharing app to improve code readability
  • Loading branch information
ChristophWurst authored Sep 27, 2023
2 parents dd3cd29 + 1144733 commit bcda331
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions apps/federatedfilesharing/lib/AddressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public function compareAddresses($user1, $server1, $user2, $server2) {
* @return string
*/
public function removeProtocolFromUrl($url) {
if (strpos($url, 'https://') === 0) {
if (str_starts_with($url, 'https://')) {
return substr($url, strlen('https://'));
} elseif (strpos($url, 'http://') === 0) {
} elseif (str_starts_with($url, 'http://')) {
return substr($url, strlen('http://'));
}

Expand All @@ -146,8 +146,8 @@ public function removeProtocolFromUrl($url) {
* @return bool
*/
public function urlContainProtocol($url) {
if (strpos($url, 'https://') === 0 ||
strpos($url, 'http://') === 0) {
if (str_starts_with($url, 'https://') ||
str_starts_with($url, 'http://')) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/federatedfilesharing/lib/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ protected function createRemoteUser(string $cloudId, string $displayName = '') {
protected function getDisplayName(ICloudId $cloudId): string {
$server = $cloudId->getRemote();
$user = $cloudId->getUser();
if (strpos($server, 'http://') === 0) {
if (str_starts_with($server, 'http://')) {
$server = substr($server, strlen('http://'));
} elseif (strpos($server, 'https://') === 0) {
} elseif (str_starts_with($server, 'https://')) {
$server = substr($server, strlen('https://'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function shareReceived(ICloudFederationShare $share) {
[$ownerUid, $remote] = $this->addressHandler->splitUserRemote($share->getOwner());
// for backward compatibility make sure that the remote url stored in the
// database ends with a trailing slash
if (substr($remote, -1) !== '/') {
if (!str_ends_with($remote, '/')) {
$remote = $remote . '/';
}

Expand Down

0 comments on commit bcda331

Please sign in to comment.