diff options
author | Faraz Samapoor <f.samapoor@gmail.com> | 2023-06-02 15:38:19 +0330 |
---|---|---|
committer | Simon L <szaimen@e.mail.de> | 2023-06-12 09:46:07 +0200 |
commit | 0bae21b1d1709e136a580b4ef2dc3cc725ca27b8 (patch) | |
tree | d86d68c9c2a7f70260863d62d7cd9c6af270e7ca /apps/dav/lib/CardDAV | |
parent | c93be182dc0172eed377ba70ce54cd7c83689764 (diff) | |
download | nextcloud-server-0bae21b1d1709e136a580b4ef2dc3cc725ca27b8.tar.gz nextcloud-server-0bae21b1d1709e136a580b4ef2dc3cc725ca27b8.zip |
Refactors "strpos" calls in /apps/dav to improve code readability.
Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
Diffstat (limited to 'apps/dav/lib/CardDAV')
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 10 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/HasPhotoPlugin.php | 4 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php | 4 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/MultiGetExportPlugin.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/PhotoCache.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/SyncService.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/SystemAddressbook.php | 2 |
7 files changed, 13 insertions, 13 deletions
diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 4e4d64f6f72..87e9cd22dac 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -1013,7 +1013,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { // Micro optimisation // don't loop through - if (strpos($cardData, 'PHOTO:data:') === 0) { + if (str_starts_with($cardData, 'PHOTO:data:')) { return $cardData; } @@ -1022,8 +1022,8 @@ class CardDavBackend implements BackendInterface, SyncSupport { $cardDataFiltered = []; $removingPhoto = false; foreach ($cardDataArray as $line) { - if (strpos($line, 'PHOTO:data:') === 0 - && strpos($line, 'PHOTO:data:image/') !== 0) { + if (str_starts_with($line, 'PHOTO:data:') + && !str_starts_with($line, 'PHOTO:data:image/')) { // Filter out PHOTO data of non-images $removingPhoto = true; $modified = true; @@ -1031,7 +1031,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { } if ($removingPhoto) { - if (strpos($line, ' ') === 0) { + if (str_starts_with($line, ' ')) { continue; } // No leading space means this is a new property @@ -1131,7 +1131,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $propertyOr = $query2->expr()->orX(); foreach ($searchProperties as $property) { if ($escapePattern) { - if ($property === 'EMAIL' && strpos($pattern, ' ') !== false) { + if ($property === 'EMAIL' && str_contains($pattern, ' ')) { // There can be no spaces in emails continue; } diff --git a/apps/dav/lib/CardDAV/HasPhotoPlugin.php b/apps/dav/lib/CardDAV/HasPhotoPlugin.php index 528fcb36bf5..310649bdae9 100644 --- a/apps/dav/lib/CardDAV/HasPhotoPlugin.php +++ b/apps/dav/lib/CardDAV/HasPhotoPlugin.php @@ -66,8 +66,8 @@ class HasPhotoPlugin extends ServerPlugin { return $vcard instanceof VCard && $vcard->PHOTO // Either the PHOTO is a url (doesn't start with data:) or the mimetype has to start with image/ - && (strpos($vcard->PHOTO->getValue(), 'data:') !== 0 - || strpos($vcard->PHOTO->getValue(), 'data:image/') === 0) + && (!str_starts_with($vcard->PHOTO->getValue(), 'data:') + || str_starts_with($vcard->PHOTO->getValue(), 'data:image/')) ; }); } diff --git a/apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php b/apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php index bd394cb7fb6..6f05bb6ce6a 100644 --- a/apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php +++ b/apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php @@ -91,7 +91,7 @@ abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties { * @return bool */ public static function isAppGeneratedAddressBook(string $uri): bool { - return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2; + return str_starts_with($uri, self::PREFIX) && substr_count($uri, self::DELIMITER) >= 2; } /** @@ -121,6 +121,6 @@ abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties { * @return bool */ public static function doesViolateReservedName(string $uri): bool { - return strpos($uri, self::PREFIX) === 0; + return str_starts_with($uri, self::PREFIX); } } diff --git a/apps/dav/lib/CardDAV/MultiGetExportPlugin.php b/apps/dav/lib/CardDAV/MultiGetExportPlugin.php index 62c4f7e8178..c3224bc5d9b 100644 --- a/apps/dav/lib/CardDAV/MultiGetExportPlugin.php +++ b/apps/dav/lib/CardDAV/MultiGetExportPlugin.php @@ -62,7 +62,7 @@ class MultiGetExportPlugin extends DAV\ServerPlugin { // Only handling xml $contentType = $response->getHeader('Content-Type'); - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { + if (!str_contains($contentType, 'application/xml') && !str_contains($contentType, 'text/xml')) { return; } diff --git a/apps/dav/lib/CardDAV/PhotoCache.php b/apps/dav/lib/CardDAV/PhotoCache.php index 101111f9310..e4d5b40fa1b 100644 --- a/apps/dav/lib/CardDAV/PhotoCache.php +++ b/apps/dav/lib/CardDAV/PhotoCache.php @@ -266,7 +266,7 @@ class PhotoCache { $typeParam = isset($params['TYPE']) ? $params['TYPE'] : $params['MEDIATYPE']; $type = $typeParam->getValue(); - if (strpos($type, 'image/') === 0) { + if (str_starts_with($type, 'image/')) { return $type; } else { return 'image/' . strtolower($type); diff --git a/apps/dav/lib/CardDAV/SyncService.php b/apps/dav/lib/CardDAV/SyncService.php index 067a279941d..09c31683069 100644 --- a/apps/dav/lib/CardDAV/SyncService.php +++ b/apps/dav/lib/CardDAV/SyncService.php @@ -157,7 +157,7 @@ class SyncService { $certPath = $this->getCertPath(); $client->setThrowExceptions(true); - if ($certPath !== '' && strpos($url, 'http://') !== 0) { + if ($certPath !== '' && !str_starts_with($url, 'http://')) { $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); } diff --git a/apps/dav/lib/CardDAV/SystemAddressbook.php b/apps/dav/lib/CardDAV/SystemAddressbook.php index 1cffde63474..5587324efcd 100644 --- a/apps/dav/lib/CardDAV/SystemAddressbook.php +++ b/apps/dav/lib/CardDAV/SystemAddressbook.php @@ -122,7 +122,7 @@ class SystemAddressbook extends AddressBook { $children = parent::getChildren(); return array_filter($children, function (Card $child) { // check only for URIs that begin with Guests: - return strpos($child->getName(), 'Guests:') !== 0; + return !str_starts_with($child->getName(), 'Guests:'); }); } |