diff options
Diffstat (limited to 'lib/private/Files/Storage/Wrapper/Encoding.php')
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encoding.php | 81 |
1 files changed, 38 insertions, 43 deletions
diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index 26e0e3a15dd..02b70e5ae60 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -35,10 +35,8 @@ class Encoding extends Wrapper { /** * Returns whether the given string is only made of ASCII characters - * - * @param string $str string */ - private function isAscii($str): bool { + private function isAscii(string $str): bool { return !preg_match('/[\\x80-\\xff]+/', $str); } @@ -47,11 +45,9 @@ class Encoding extends Wrapper { * each form for each path section and returns the correct form. * If no existing path found, returns the path as it was given. * - * @param string $fullPath path to check - * * @return string original or converted path */ - private function findPathToUse($fullPath): string { + private function findPathToUse(string $fullPath): string { $cachedPath = $this->namesCache[$fullPath]; if ($cachedPath !== null) { return $cachedPath; @@ -75,12 +71,11 @@ class Encoding extends Wrapper { * Checks whether the last path section of the given path exists in NFC or NFD form * and returns the correct form. If no existing path found, returns null. * - * @param string $basePath base path to check * @param string $lastSection last section of the path to check for NFD/NFC variations * * @return string|null original or converted path, or null if none of the forms was found */ - private function findPathToUseLastSection($basePath, $lastSection): ?string { + private function findPathToUseLastSection(string $basePath, string $lastSection): ?string { $fullPath = $basePath . $lastSection; if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) { $this->namesCache[$fullPath] = $fullPath; @@ -104,7 +99,7 @@ class Encoding extends Wrapper { return null; } - public function mkdir($path): bool { + public function mkdir(string $path): bool { // note: no conversion here, method should not be called with non-NFC names! $result = $this->storage->mkdir($path); if ($result) { @@ -113,7 +108,7 @@ class Encoding extends Wrapper { return $result; } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $result = $this->storage->rmdir($this->findPathToUse($path)); if ($result) { unset($this->namesCache[$path]); @@ -121,72 +116,72 @@ class Encoding extends Wrapper { return $result; } - public function opendir($path) { + public function opendir(string $path) { $handle = $this->storage->opendir($this->findPathToUse($path)); return EncodingDirectoryWrapper::wrap($handle); } - public function is_dir($path): bool { + public function is_dir(string $path): bool { return $this->storage->is_dir($this->findPathToUse($path)); } - public function is_file($path): bool { + public function is_file(string $path): bool { return $this->storage->is_file($this->findPathToUse($path)); } - public function stat($path): array|false { + public function stat(string $path): array|false { return $this->storage->stat($this->findPathToUse($path)); } - public function filetype($path): string|false { + public function filetype(string $path): string|false { return $this->storage->filetype($this->findPathToUse($path)); } - public function filesize($path): int|float|false { + public function filesize(string $path): int|float|false { return $this->storage->filesize($this->findPathToUse($path)); } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { return $this->storage->isCreatable($this->findPathToUse($path)); } - public function isReadable($path): bool { + public function isReadable(string $path): bool { return $this->storage->isReadable($this->findPathToUse($path)); } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return $this->storage->isUpdatable($this->findPathToUse($path)); } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { return $this->storage->isDeletable($this->findPathToUse($path)); } - public function isSharable($path): bool { + public function isSharable(string $path): bool { return $this->storage->isSharable($this->findPathToUse($path)); } - public function getPermissions($path): int { + public function getPermissions(string $path): int { return $this->storage->getPermissions($this->findPathToUse($path)); } - public function file_exists($path): bool { + public function file_exists(string $path): bool { return $this->storage->file_exists($this->findPathToUse($path)); } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { return $this->storage->filemtime($this->findPathToUse($path)); } - public function file_get_contents($path): string|false { + public function file_get_contents(string $path): string|false { return $this->storage->file_get_contents($this->findPathToUse($path)); } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { return $this->storage->file_put_contents($this->findPathToUse($path), $data); } - public function unlink($path): bool { + public function unlink(string $path): bool { $result = $this->storage->unlink($this->findPathToUse($path)); if ($result) { unset($this->namesCache[$path]); @@ -194,16 +189,16 @@ class Encoding extends Wrapper { return $result; } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { // second name always NFC return $this->storage->rename($this->findPathToUse($source), $this->findPathToUse($target)); } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { return $this->storage->copy($this->findPathToUse($source), $this->findPathToUse($target)); } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $result = $this->storage->fopen($this->findPathToUse($path), $mode); if ($result && $mode !== 'r' && $mode !== 'rb') { unset($this->namesCache[$path]); @@ -211,49 +206,49 @@ class Encoding extends Wrapper { return $result; } - public function getMimeType($path): string|false { + public function getMimeType(string $path): string|false { return $this->storage->getMimeType($this->findPathToUse($path)); } - public function hash($type, $path, $raw = false): string|false { + public function hash(string $type, string $path, bool $raw = false): string|false { return $this->storage->hash($type, $this->findPathToUse($path), $raw); } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { return $this->storage->free_space($this->findPathToUse($path)); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { return $this->storage->touch($this->findPathToUse($path), $mtime); } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { return $this->storage->getLocalFile($this->findPathToUse($path)); } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { return $this->storage->hasUpdated($this->findPathToUse($path), $time); } - public function getCache($path = '', $storage = null): \OCP\Files\Cache\ICache { + public function getCache(string $path = '', ?IStorage $storage = null): \OCP\Files\Cache\ICache { if (!$storage) { $storage = $this; } return $this->storage->getCache($this->findPathToUse($path), $storage); } - public function getScanner($path = '', $storage = null): IScanner { + public function getScanner(string $path = '', ?IStorage $storage = null): IScanner { if (!$storage) { $storage = $this; } return $this->storage->getScanner($this->findPathToUse($path), $storage); } - public function getETag($path): string|false { + public function getETag(string $path): string|false { return $this->storage->getETag($this->findPathToUse($path)); } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath)); } @@ -265,7 +260,7 @@ class Encoding extends Wrapper { return $result; } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($sourceStorage === $this) { $result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath)); if ($result) { @@ -283,13 +278,13 @@ class Encoding extends Wrapper { return $result; } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { $entry = $this->storage->getMetaData($this->findPathToUse($path)); $entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/'); return $entry; } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { $entries = $this->storage->getDirectoryContent($this->findPathToUse($directory)); foreach ($entries as $entry) { $entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/'); |