]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactors "substr" calls to improve code readability 39214/head
authorHamid Dehnavi <hamid.dev.pro@gmail.com>
Fri, 7 Jul 2023 01:07:57 +0000 (04:37 +0330)
committerJohn Molakvoæ <skjnldsv@users.noreply.github.com>
Fri, 23 Feb 2024 14:54:10 +0000 (15:54 +0100)
Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
apps/dav/lib/BulkUpload/MultipartRequestParser.php
apps/dav/lib/CalDAV/BirthdayService.php
apps/dav/lib/Connector/Sabre/FakeLockerPlugin.php
apps/dav/lib/Connector/Sabre/Node.php
apps/dav/lib/Connector/Sabre/Principal.php
apps/dav/lib/DAV/CustomPropertiesBackend.php
apps/dav/tests/unit/Connector/Sabre/FileTest.php

index 2541ea8f333378b26d84f203cd01aae8f9c47257..7c977b42ccbca361479bf7af2f4547542d18af28 100644 (file)
@@ -82,7 +82,7 @@ class MultipartRequestParser {
                $boundaryValue = trim($boundaryValue);
 
                // Remove potential quotes around boundary value.
-               if (substr($boundaryValue, 0, 1) === '"' && substr($boundaryValue, -1) === '"') {
+               if (str_starts_with($boundaryValue, '"') && str_ends_with($boundaryValue, '"')) {
                        $boundaryValue = substr($boundaryValue, 1, -1);
                }
 
index 95176283f11d445399b58cc948f41171fb1e85a2..5d1d55879ca3f3e2fc76d578ebd0c16912101865 100644 (file)
@@ -419,7 +419,7 @@ class BirthdayService {
         * @return string|null
         */
        private function principalToUserId(string $userPrincipal):?string {
-               if (substr($userPrincipal, 0, 17) === 'principals/users/') {
+               if (str_starts_with($userPrincipal, 'principals/users/')) {
                        return substr($userPrincipal, 17);
                }
                return null;
index b61e9dc0c39b6fa3f247a39afcdf23a0c27fd7bb..c63b1cf50f2d5a62cb6e7dfcc9fedcf9d8c738a8 100644 (file)
@@ -108,7 +108,7 @@ class FakeLockerPlugin extends ServerPlugin {
                        if (isset($fileCondition['tokens'])) {
                                foreach ($fileCondition['tokens'] as &$token) {
                                        if (isset($token['token'])) {
-                                               if (substr($token['token'], 0, 16) === 'opaquelocktoken:') {
+                                               if (str_starts_with($token['token'], 'opaquelocktoken:')) {
                                                        $token['validToken'] = true;
                                                }
                                        }
index c9407b127860d7fde7b5200faa1c636b22d5a835..5237064b46f017740fa629ff03bb380ead5a58fc 100644 (file)
@@ -303,7 +303,7 @@ abstract class Node implements \Sabre\DAV\INode {
                $mountpoint = $this->info->getMountPoint();
                if (!($mountpoint instanceof MoveableMount)) {
                        $mountpointpath = $mountpoint->getMountPoint();
-                       if (substr($mountpointpath, -1) === '/') {
+                       if (str_ends_with($mountpointpath, '/')) {
                                $mountpointpath = substr($mountpointpath, 0, -1);
                        }
 
index df1de17fe200bfe02c3535087f42ed7a4ed4cc68..9d9cfbe43cbf6a72f5e06668c7b3b4d984f5d7fb 100644 (file)
@@ -505,7 +505,7 @@ class Principal implements BackendInterface {
                                return $this->principalPrefix . '/' . $user->getUID();
                        }
                }
-               if (substr($uri, 0, 10) === 'principal:') {
+               if (str_starts_with($uri, 'principal:')) {
                        $principal = substr($uri, 10);
                        $principal = $this->getPrincipalByPath($principal);
                        if ($principal !== null) {
index 311fe0ea561f0eaa7496fc4cb38e06e060fff5b0..e76a71aec637f259eef8ef62aac05bd02e8fa7e3 100644 (file)
@@ -166,7 +166,7 @@ class CustomPropertiesBackend implements BackendInterface {
 
                // substr of calendars/ => path is inside the CalDAV component
                // two '/' => this a calendar (no calendar-home nor calendar object)
-               if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) {
+               if (str_starts_with($path, 'calendars/') && substr_count($path, '/') === 2) {
                        $allRequestedProps = $propFind->getRequestedProperties();
                        $customPropertiesForShares = [
                                '{DAV:}displayname',
index 884245afa3bb27018dea5b5fa31c6545f899fd58..36dc550a8a39231d029270221e18d8a5dabc2b2e 100644 (file)
@@ -1134,7 +1134,7 @@ class FileTest extends TestCase {
                        $realPath = $storage->getSourcePath($internalPath);
                        $dh = opendir($realPath);
                        while (($file = readdir($dh)) !== false) {
-                               if (substr($file, strlen($file) - 5, 5) === '.part') {
+                               if (str_ends_with($file, '.part')) {
                                        $files[] = $file;
                                }
                        }