diff options
author | Faraz Samapoor <fsamapoor@gmail.com> | 2023-05-15 15:17:19 +0330 |
---|---|---|
committer | Faraz Samapoor <fsamapoor@gmail.com> | 2023-05-15 15:17:19 +0330 |
commit | e7cc7653b885c49b1b3f0a78f91ea05a53e102d8 (patch) | |
tree | 42da61d5c6e988d7c9eff7e081327a73f661dc89 /lib/private/Files/Storage | |
parent | 8bdb50fd507bfe68161ab98eba903872083ea4f3 (diff) | |
download | nextcloud-server-e7cc7653b885c49b1b3f0a78f91ea05a53e102d8.tar.gz nextcloud-server-e7cc7653b885c49b1b3f0a78f91ea05a53e102d8.zip |
Refactors "strpos" calls in lib/private to improve code readability.
Signed-off-by: Faraz Samapoor <fsamapoor@gmail.com>
Diffstat (limited to 'lib/private/Files/Storage')
-rw-r--r-- | lib/private/Files/Storage/Common.php | 2 | ||||
-rw-r--r-- | lib/private/Files/Storage/DAV.php | 8 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encryption.php | 4 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Jail.php | 2 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Quota.php | 4 |
5 files changed, 10 insertions, 10 deletions
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index cd9a05a2a1d..5ab411434d0 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -577,7 +577,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { */ private function scanForInvalidCharacters($fileName, $invalidChars) { foreach (str_split($invalidChars) as $char) { - if (strpos($fileName, $char) !== false) { + if (str_contains($fileName, $char)) { throw new InvalidCharacterInPathException(); } } diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index b332f3b7c4a..6a05f54a0b4 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -769,16 +769,16 @@ class DAV extends Common { */ protected function parsePermissions($permissionsString) { $permissions = Constants::PERMISSION_READ; - if (strpos($permissionsString, 'R') !== false) { + if (str_contains($permissionsString, 'R')) { $permissions |= Constants::PERMISSION_SHARE; } - if (strpos($permissionsString, 'D') !== false) { + if (str_contains($permissionsString, 'D')) { $permissions |= Constants::PERMISSION_DELETE; } - if (strpos($permissionsString, 'W') !== false) { + if (str_contains($permissionsString, 'W')) { $permissions |= Constants::PERMISSION_UPDATE; } - if (strpos($permissionsString, 'CK') !== false) { + if (str_contains($permissionsString, 'CK')) { $permissions |= Constants::PERMISSION_CREATE; $permissions |= Constants::PERMISSION_UPDATE; } diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 9c0e6c91463..ab3873a7ec0 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -922,7 +922,7 @@ class Encryption extends Wrapper { } $firstBlock = $this->readFirstBlock($path); - if (substr($firstBlock, 0, strlen(Util::HEADER_START)) === Util::HEADER_START) { + if (str_starts_with($firstBlock, Util::HEADER_START)) { $headerSize = $this->util->getHeaderSize(); } @@ -937,7 +937,7 @@ class Encryption extends Wrapper { */ protected function parseRawHeader($rawHeader) { $result = []; - if (substr($rawHeader, 0, strlen(Util::HEADER_START)) === Util::HEADER_START) { + if (str_starts_with($rawHeader, Util::HEADER_START)) { $header = $rawHeader; $endAt = strpos($header, Util::HEADER_END); if ($endAt !== false) { diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index caf039d4cca..1921ac27848 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -72,7 +72,7 @@ class Jail extends Wrapper { public function getJailedPath($path) { $root = rtrim($this->rootPath, '/') . '/'; - if ($path !== $this->rootPath && strpos($path, $root) !== 0) { + if ($path !== $this->rootPath && !str_starts_with($path, $root)) { return null; } else { $path = substr($path, strlen($this->rootPath)); diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index cfb2c455a2c..5786dba5114 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -109,7 +109,7 @@ class Quota extends Wrapper { if (!$this->hasQuota()) { return $this->storage->free_space($path); } - if ($this->getQuota() < 0 || strpos($path, 'cache') === 0 || strpos($path, 'uploads') === 0) { + if ($this->getQuota() < 0 || str_starts_with($path, 'cache') || str_starts_with($path, 'uploads')) { return $this->storage->free_space($path); } else { $used = $this->getSize($this->sizeRoot); @@ -207,7 +207,7 @@ class Quota extends Wrapper { * Only apply quota for files, not metadata, trash or others */ private function shouldApplyQuota(string $path): bool { - return strpos(ltrim($path, '/'), 'files/') === 0; + return str_starts_with(ltrim($path, '/'), 'files/'); } /** |