Skip to content

Commit bcda331

Browse files
Merge pull request #39213 from shdehnavi/replace_strpos_and_substr_calls_in_federatedfilesharing_app
Refactor "strpos" and "substr" calls in federatedfilesharing app to improve code readability
2 parents dd3cd29 + 1144733 commit bcda331

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

apps/federatedfilesharing/lib/AddressHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ public function compareAddresses($user1, $server1, $user2, $server2) {
130130
* @return string
131131
*/
132132
public function removeProtocolFromUrl($url) {
133-
if (strpos($url, 'https://') === 0) {
133+
if (str_starts_with($url, 'https://')) {
134134
return substr($url, strlen('https://'));
135-
} elseif (strpos($url, 'http://') === 0) {
135+
} elseif (str_starts_with($url, 'http://')) {
136136
return substr($url, strlen('http://'));
137137
}
138138

@@ -146,8 +146,8 @@ public function removeProtocolFromUrl($url) {
146146
* @return bool
147147
*/
148148
public function urlContainProtocol($url) {
149-
if (strpos($url, 'https://') === 0 ||
150-
strpos($url, 'http://') === 0) {
149+
if (str_starts_with($url, 'https://') ||
150+
str_starts_with($url, 'http://')) {
151151
return true;
152152
}
153153

apps/federatedfilesharing/lib/Notifier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ protected function createRemoteUser(string $cloudId, string $displayName = '') {
202202
protected function getDisplayName(ICloudId $cloudId): string {
203203
$server = $cloudId->getRemote();
204204
$user = $cloudId->getUser();
205-
if (strpos($server, 'http://') === 0) {
205+
if (str_starts_with($server, 'http://')) {
206206
$server = substr($server, strlen('http://'));
207-
} elseif (strpos($server, 'https://') === 0) {
207+
} elseif (str_starts_with($server, 'https://')) {
208208
$server = substr($server, strlen('https://'));
209209
}
210210

apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function shareReceived(ICloudFederationShare $share) {
116116
[$ownerUid, $remote] = $this->addressHandler->splitUserRemote($share->getOwner());
117117
// for backward compatibility make sure that the remote url stored in the
118118
// database ends with a trailing slash
119-
if (substr($remote, -1) !== '/') {
119+
if (!str_ends_with($remote, '/')) {
120120
$remote = $remote . '/';
121121
}
122122

0 commit comments

Comments
 (0)