From 14e67345472e163be1ec28f70c4f0f2e3596f8f5 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 1 Oct 2024 16:14:28 +0200 Subject: [PATCH] refactor(files_external): Add Storage parameter strong types Signed-off-by: provokateurin --- .../lib/Lib/Storage/AmazonS3.php | 54 +++++++------- apps/files_external/lib/Lib/Storage/FTP.php | 37 +++++----- apps/files_external/lib/Lib/Storage/SFTP.php | 46 +++++------- .../lib/Lib/Storage/SFTPReadStream.php | 5 +- .../lib/Lib/Storage/SFTPWriteStream.php | 3 +- apps/files_external/lib/Lib/Storage/SMB.php | 71 +++++++------------ .../lib/Lib/Storage/StreamWrapper.php | 37 ++++------ apps/files_external/lib/Lib/Storage/Swift.php | 38 ++++------ 8 files changed, 116 insertions(+), 175 deletions(-) diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index b2d6d24db5e..be07314311e 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -59,11 +59,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { $this->logger = Server::get(LoggerInterface::class); } - /** - * @param string $path - * @return string correctly encoded path - */ - private function normalizePath($path): string { + private function normalizePath(string $path): string { $path = trim($path, '/'); if (!$path) { @@ -73,11 +69,11 @@ class AmazonS3 extends \OC\Files\Storage\Common { return $path; } - private function isRoot($path): bool { + private function isRoot(string $path): bool { return $path === '.'; } - private function cleanKey($path): string { + private function cleanKey(string $path): string { if ($this->isRoot($path)) { return '/'; } @@ -90,7 +86,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { $this->filesCache = new CappedMemoryCache(); } - private function invalidateCache($key): void { + private function invalidateCache(string $key): void { unset($this->objectCache[$key]); $keys = array_keys($this->objectCache->getData()); $keyLength = strlen($key); @@ -143,7 +139,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { * * @throws \Exception */ - private function doesDirectoryExist($path): bool { + private function doesDirectoryExist(string $path): bool { if ($path === '.' || $path === '') { return true; } @@ -185,7 +181,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return false; } - protected function remove($path): bool { + protected function remove(string $path): bool { // remember fileType to reduce http calls $fileType = $this->filetype($path); if ($fileType === 'dir') { @@ -197,7 +193,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -225,12 +221,12 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function file_exists($path): bool { + public function file_exists(string $path): bool { return $this->filetype($path) !== false; } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $path = $this->normalizePath($path); if ($this->isRoot($path)) { @@ -250,7 +246,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return $this->batchDelete(); } - private function batchDelete($path = null): bool { + private function batchDelete(?string $path = null): bool { // TODO explore using https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.BatchDelete.html $params = [ 'Bucket' => $this->bucket @@ -290,7 +286,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function opendir($path) { + public function opendir(string $path) { try { $content = iterator_to_array($this->getDirectoryContent($path)); return IteratorDirectory::wrap(array_map(function (array $item) { @@ -301,7 +297,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } } - public function stat($path): array|false { + public function stat(string $path): array|false { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -324,7 +320,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { * When the information is already present (e.g. opendir has been called before) * this value is return. Otherwise a headObject is emitted. */ - private function getContentLength($path): int { + private function getContentLength(string $path): int { if (isset($this->filesCache[$path])) { return (int)$this->filesCache[$path]['ContentLength']; } @@ -343,7 +339,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { * When the information is already present (e.g. opendir has been called before) * this value is return. Otherwise a headObject is emitted. */ - private function getLastModified($path): string { + private function getLastModified(string $path): string { if (isset($this->filesCache[$path])) { return $this->filesCache[$path]['LastModified']; } @@ -356,7 +352,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return 'now'; } - public function is_dir($path): bool { + public function is_dir(string $path): bool { $path = $this->normalizePath($path); if (isset($this->filesCache[$path])) { @@ -374,7 +370,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } } - public function filetype($path): string|false { + public function filetype(string $path): string|false { $path = $this->normalizePath($path); if ($this->isRoot($path)) { @@ -402,7 +398,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return false; } - public function getPermissions($path): int { + public function getPermissions(string $path): int { $type = $this->filetype($path); if (!$type) { return 0; @@ -410,7 +406,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return $type === 'dir' ? Constants::PERMISSION_ALL : Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE; } - public function unlink($path): bool { + public function unlink(string $path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -431,7 +427,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $path = $this->normalizePath($path); switch ($mode) { @@ -489,7 +485,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return false; } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { if (is_null($mtime)) { $mtime = time(); } @@ -524,7 +520,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function copy($source, $target, $isFile = null): bool { + public function copy(string $source, string $target, ?bool $isFile = null): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -567,7 +563,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -605,7 +601,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return $this->id; } - public function writeBack($tmpFile, $path): bool { + public function writeBack(string $tmpFile, string $path): bool { try { $source = fopen($tmpFile, 'r'); $this->writeObject($path, $source, $this->mimeDetector->detectPath($path)); @@ -629,7 +625,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { $path = $this->normalizePath($directory); if ($this->isRoot($path)) { @@ -726,7 +722,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { // for files we can get the proper mtime if ($path !== '' && $object = $this->headObject($path)) { $stat = $this->objectToMetaData($object); diff --git a/apps/files_external/lib/Lib/Storage/FTP.php b/apps/files_external/lib/Lib/Storage/FTP.php index 514492156b6..142fa746184 100644 --- a/apps/files_external/lib/Lib/Storage/FTP.php +++ b/apps/files_external/lib/Lib/Storage/FTP.php @@ -82,7 +82,7 @@ class FTP extends Common { return 'ftp::' . $this->username . '@' . $this->host . '/' . $this->root; } - protected function buildPath($path): string { + protected function buildPath(string $path): string { return rtrim($this->root . '/' . $path, '/'); } @@ -94,7 +94,7 @@ class FTP extends Common { } } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { $result = $this->getConnection()->mdtm($this->buildPath($path)); if ($result === -1) { @@ -126,7 +126,7 @@ class FTP extends Common { } } - public function filesize($path): false|int|float { + public function filesize(string $path): false|int|float { $result = $this->getConnection()->size($this->buildPath($path)); if ($result === -1) { return false; @@ -135,7 +135,7 @@ class FTP extends Common { } } - public function rmdir($path): bool { + public function rmdir(string $path): bool { if ($this->is_dir($path)) { $result = $this->getConnection()->rmdir($this->buildPath($path)); // recursive rmdir support depends on the ftp server @@ -151,10 +151,7 @@ class FTP extends Common { } } - /** - * @param string $path - */ - private function recursiveRmDir($path): bool { + private function recursiveRmDir(string $path): bool { $contents = $this->getDirectoryContent($path); $result = true; foreach ($contents as $content) { @@ -177,7 +174,7 @@ class FTP extends Common { } } - public function stat($path): array|false { + public function stat(string $path): array|false { if (!$this->file_exists($path)) { return false; } @@ -187,14 +184,14 @@ class FTP extends Common { ]; } - public function file_exists($path): bool { + public function file_exists(string $path): bool { if ($path === '' || $path === '.' || $path === '/') { return true; } return $this->filetype($path) !== false; } - public function unlink($path): bool { + public function unlink(string $path): bool { switch ($this->filetype($path)) { case 'dir': return $this->rmdir($path); @@ -205,19 +202,19 @@ class FTP extends Common { } } - public function opendir($path) { + public function opendir(string $path) { $files = $this->getConnection()->nlist($this->buildPath($path)); return IteratorDirectory::wrap($files); } - public function mkdir($path): bool { + public function mkdir(string $path): bool { if ($this->is_dir($path)) { return false; } return $this->getConnection()->mkdir($this->buildPath($path)) !== false; } - public function is_dir($path): bool { + public function is_dir(string $path): bool { if ($path === '') { return true; } @@ -229,11 +226,11 @@ class FTP extends Common { } } - public function is_file($path): bool { + public function is_file(string $path): bool { return $this->filesize($path) !== false; } - public function filetype($path): string|false { + public function filetype(string $path): string|false { if ($this->is_dir($path)) { return 'dir'; } elseif ($this->is_file($path)) { @@ -243,7 +240,7 @@ class FTP extends Common { } } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $useExisting = true; switch ($mode) { case 'r': @@ -309,7 +306,7 @@ class FTP extends Common { return $stream; } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { if ($this->file_exists($path)) { return false; } else { @@ -318,12 +315,12 @@ class FTP extends Common { } } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $this->unlink($target); return $this->getConnection()->rename($this->buildPath($source), $this->buildPath($target)); } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { $files = $this->getConnection()->mlsd($this->buildPath($directory)); $mimeTypeDetector = \OC::$server->getMimeTypeDetector(); diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php index c8e01a058ff..e5188db9bcc 100644 --- a/apps/files_external/lib/Lib/Storage/SFTP.php +++ b/apps/files_external/lib/Lib/Storage/SFTP.php @@ -39,7 +39,7 @@ class SFTP extends Common { * @param string $host protocol://server:port * @return array [$server, $port] */ - private function splitHost($host): array { + private function splitHost(string $host): array { $input = $host; if (!str_contains($host, '://')) { // add a protocol to fix parse_url behavior with ipv6 @@ -163,10 +163,7 @@ class SFTP extends Common { return $this->user; } - /** - * @param string $path - */ - private function absPath($path): string { + private function absPath(string $path): string { return $this->root . $this->cleanPath($path); } @@ -185,7 +182,7 @@ class SFTP extends Common { return false; } - protected function writeHostKeys($keys): bool { + protected function writeHostKeys(array $keys): bool { try { $keyPath = $this->hostKeysPath(); if ($keyPath && file_exists($keyPath)) { @@ -224,7 +221,7 @@ class SFTP extends Common { return []; } - public function mkdir($path): bool { + public function mkdir(string $path): bool { try { return $this->getConnection()->mkdir($this->absPath($path)); } catch (\Exception $e) { @@ -232,7 +229,7 @@ class SFTP extends Common { } } - public function rmdir($path): bool { + public function rmdir(string $path): bool { try { $result = $this->getConnection()->delete($this->absPath($path), true); // workaround: stray stat cache entry when deleting empty folders @@ -244,7 +241,7 @@ class SFTP extends Common { } } - public function opendir($path) { + public function opendir(string $path) { try { $list = $this->getConnection()->nlist($this->absPath($path)); if ($list === false) { @@ -264,7 +261,7 @@ class SFTP extends Common { } } - public function filetype($path): string|false { + public function filetype(string $path): string|false { try { $stat = $this->getConnection()->stat($this->absPath($path)); if (!is_array($stat) || !array_key_exists('type', $stat)) { @@ -282,7 +279,7 @@ class SFTP extends Common { return false; } - public function file_exists($path): bool { + public function file_exists(string $path): bool { try { return $this->getConnection()->stat($this->absPath($path)) !== false; } catch (\Exception $e) { @@ -290,7 +287,7 @@ class SFTP extends Common { } } - public function unlink($path): bool { + public function unlink(string $path): bool { try { return $this->getConnection()->delete($this->absPath($path), true); } catch (\Exception $e) { @@ -298,7 +295,7 @@ class SFTP extends Common { } } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { try { $absPath = $this->absPath($path); $connection = $this->getConnection(); @@ -339,7 +336,7 @@ class SFTP extends Common { return false; } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { try { if (!is_null($mtime)) { return false; @@ -356,15 +353,13 @@ class SFTP extends Common { } /** - * @param string $path - * @param string $target * @throws \Exception */ - public function getFile($path, $target): void { + public function getFile(string $path, string $target): void { $this->getConnection()->get($path, $target); } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { try { if ($this->file_exists($target)) { $this->unlink($target); @@ -381,7 +376,7 @@ class SFTP extends Common { /** * @return array{mtime: int, size: int, ctime: int}|false */ - public function stat($path): array|false { + public function stat(string $path): array|false { try { $stat = $this->getConnection()->stat($this->absPath($path)); @@ -398,10 +393,7 @@ class SFTP extends Common { } } - /** - * @param string $path - */ - public function constructUrl($path): string { + public function constructUrl(string $path): string { // Do not pass the password here. We want to use the Net_SFTP object // supplied via stream context or fail. We only supply username and // hostname because this might show up in logs (they are not used). @@ -409,7 +401,7 @@ class SFTP extends Common { return $url; } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { /** @psalm-suppress InternalMethod */ $result = $this->getConnection()->put($this->absPath($path), $data); if ($result) { @@ -441,7 +433,7 @@ class SFTP extends Common { } } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { if ($this->is_dir($source) || $this->is_dir($target)) { return parent::copy($source, $target); } else { @@ -468,7 +460,7 @@ class SFTP extends Common { } } - public function getPermissions($path): int { + public function getPermissions(string $path): int { $stat = $this->getConnection()->stat($this->absPath($path)); if (!$stat) { return 0; @@ -480,7 +472,7 @@ class SFTP extends Common { } } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { $stat = $this->getConnection()->stat($this->absPath($path)); if (!$stat) { return null; diff --git a/apps/files_external/lib/Lib/Storage/SFTPReadStream.php b/apps/files_external/lib/Lib/Storage/SFTPReadStream.php index e0b4b4002aa..7dedbd7035a 100644 --- a/apps/files_external/lib/Lib/Storage/SFTPReadStream.php +++ b/apps/files_external/lib/Lib/Storage/SFTPReadStream.php @@ -44,10 +44,9 @@ class SFTPReadStream implements File { /** * Load the source from the stream context and return the context options * - * @param string $name * @throws \BadMethodCallException */ - protected function loadContext($name) { + protected function loadContext(string $name) { $context = stream_context_get_options($this->context); if (isset($context[$name])) { $context = $context[$name]; @@ -146,7 +145,7 @@ class SFTPReadStream implements File { return $data; } - private function request_chunk($size) { + private function request_chunk(int $size) { if ($this->pendingRead) { $this->sftp->_get_sftp_packet(); } diff --git a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php index a652a83cb83..d64e89b5462 100644 --- a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php +++ b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php @@ -42,10 +42,9 @@ class SFTPWriteStream implements File { /** * Load the source from the stream context and return the context options * - * @param string $name * @throws \BadMethodCallException */ - protected function loadContext($name) { + protected function loadContext(string $name) { $context = stream_context_get_options($this->context); if (isset($context[$name])) { $context = $context[$name]; diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 4fd64cd8ea0..0946a3d0135 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -120,7 +120,7 @@ class SMB extends Common implements INotifyStorage { parent::__construct($params); } - private function splitUser($user): array { + private function splitUser(string $user): array { if (str_contains($user, '/')) { return explode('/', $user, 2); } elseif (str_contains($user, '\\')) { @@ -137,14 +137,11 @@ class SMB extends Common implements INotifyStorage { return 'smb::' . $this->server->getAuth()->getUsername() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root; } - /** - * @param string $path - */ - protected function buildPath($path): string { + protected function buildPath(string $path): string { return Filesystem::normalizePath($this->root . '/' . $path, true, false, true); } - protected function relativePath($fullPath): ?string { + protected function relativePath(string $fullPath): ?string { if ($fullPath === $this->root) { return ''; } elseif (substr($fullPath, 0, strlen($this->root)) === $this->root) { @@ -155,12 +152,11 @@ class SMB extends Common implements INotifyStorage { } /** - * @param string $path * @throws StorageAuthException * @throws \OCP\Files\NotFoundException * @throws \OCP\Files\ForbiddenException */ - protected function getFileInfo($path): IFileInfo { + protected function getFileInfo(string $path): IFileInfo { try { $path = $this->buildPath($path); $cached = $this->statCache[$path] ?? null; @@ -186,7 +182,6 @@ class SMB extends Common implements INotifyStorage { } /** - * @param \Exception $e * @throws StorageAuthException */ protected function throwUnavailable(\Exception $e): never { @@ -196,8 +191,6 @@ class SMB extends Common implements INotifyStorage { /** * get the acl from fileinfo that is relevant for the configured user - * - * @param IFileInfo $file */ private function getACL(IFileInfo $file): ?ACL { $acls = $file->getAcls(); @@ -212,11 +205,10 @@ class SMB extends Common implements INotifyStorage { } /** - * @param string $path * @return \Generator * @throws StorageNotAvailableException */ - protected function getFolderContents($path): iterable { + protected function getFolderContents(string $path): iterable { try { $path = ltrim($this->buildPath($path), '/'); try { @@ -267,10 +259,7 @@ class SMB extends Common implements INotifyStorage { } } - /** - * @param IFileInfo $info - */ - protected function formatInfo($info): array { + protected function formatInfo(IFileInfo $info): array { $result = [ 'size' => $info->getSize(), 'mtime' => $info->getMTime(), @@ -289,7 +278,7 @@ class SMB extends Common implements INotifyStorage { * @param string $source the old name of the path * @param string $target the new name of the path */ - public function rename($source, $target, $retry = true): bool { + public function rename(string $source, string $target, bool $retry = true): bool { if ($this->isRootDir($source) || $this->isRootDir($target)) { return false; } @@ -328,7 +317,7 @@ class SMB extends Common implements INotifyStorage { return $result; } - public function stat($path, $retry = true): array|false { + public function stat(string $path, bool $retry = true): array|false { try { $result = $this->formatInfo($this->getFileInfo($path)); } catch (\OCP\Files\ForbiddenException $e) { @@ -370,10 +359,8 @@ class SMB extends Common implements INotifyStorage { /** * Check if the path is our root dir (not the smb one) - * - * @param string $path the path */ - private function isRootDir($path): bool { + private function isRootDir(string $path): bool { return $path === '' || $path === '/' || $path === '.'; } @@ -384,10 +371,7 @@ class SMB extends Common implements INotifyStorage { return $this->share->getName() && (!$this->root || $this->root === '/'); } - /** - * @param string $path - */ - public function unlink($path): bool { + public function unlink(string $path): bool { if ($this->isRootDir($path)) { return false; } @@ -413,11 +397,8 @@ class SMB extends Common implements INotifyStorage { /** * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time */ - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { if (!$path and $this->root === '/') { // mtime doesn't work for shares, but giving the nature of the backend, // doing a full update is still just fast enough @@ -429,11 +410,9 @@ class SMB extends Common implements INotifyStorage { } /** - * @param string $path - * @param string $mode * @return resource|false */ - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $fullPath = $this->buildPath($path); try { switch ($mode) { @@ -497,7 +476,7 @@ class SMB extends Common implements INotifyStorage { } } - public function rmdir($path): bool { + public function rmdir(string $path): bool { if ($this->isRootDir($path)) { return false; } @@ -524,7 +503,7 @@ class SMB extends Common implements INotifyStorage { } } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { try { if (!$this->file_exists($path)) { $fh = $this->share->write($this->buildPath($path)); @@ -540,7 +519,7 @@ class SMB extends Common implements INotifyStorage { } } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { try { $fileInfo = $this->getFileInfo($path); } catch (\OCP\Files\NotFoundException $e) { @@ -585,7 +564,7 @@ class SMB extends Common implements INotifyStorage { return $data; } - public function opendir($path) { + public function opendir(string $path) { try { $files = $this->getFolderContents($path); } catch (NotFoundException $e) { @@ -600,7 +579,7 @@ class SMB extends Common implements INotifyStorage { return IteratorDirectory::wrap($names); } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { try { $files = $this->getFolderContents($directory); foreach ($files as $file) { @@ -613,7 +592,7 @@ class SMB extends Common implements INotifyStorage { } } - public function filetype($path): string|false { + public function filetype(string $path): string|false { try { return $this->getFileInfo($path)->isDirectory() ? 'dir' : 'file'; } catch (\OCP\Files\NotFoundException $e) { @@ -623,7 +602,7 @@ class SMB extends Common implements INotifyStorage { } } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $path = $this->buildPath($path); try { $this->share->mkdir($path); @@ -636,7 +615,7 @@ class SMB extends Common implements INotifyStorage { } } - public function file_exists($path): bool { + public function file_exists(string $path): bool { try { // Case sensitive filesystem doesn't matter for root directory if ($this->caseSensitive === false && $path !== '') { @@ -660,7 +639,7 @@ class SMB extends Common implements INotifyStorage { } } - public function isReadable($path): bool { + public function isReadable(string $path): bool { try { $info = $this->getFileInfo($path); return $this->showHidden || !$info->isHidden(); @@ -671,7 +650,7 @@ class SMB extends Common implements INotifyStorage { } } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { try { $info = $this->getFileInfo($path); // following windows behaviour for read-only folders: they can be written into @@ -684,7 +663,7 @@ class SMB extends Common implements INotifyStorage { } } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { try { $info = $this->getFileInfo($path); return ($this->showHidden || !$info->isHidden()) && !$info->isReadOnly(); @@ -716,7 +695,7 @@ class SMB extends Common implements INotifyStorage { } } - public function listen($path, callable $callback): void { + public function listen(string $path, callable $callback): void { $this->notify($path)->listen(function (IChange $change) use ($callback) { if ($change instanceof IRenameChange) { return $callback($change->getType(), $change->getPath(), $change->getTargetPath()); @@ -726,7 +705,7 @@ class SMB extends Common implements INotifyStorage { }); } - public function notify($path): SMBNotifyHandler { + public function notify(string $path): SMBNotifyHandler { $path = '/' . ltrim($path, '/'); $shareNotifyHandler = $this->share->notify($this->buildPath($path)); return new SMBNotifyHandler($shareNotifyHandler, $this->root); diff --git a/apps/files_external/lib/Lib/Storage/StreamWrapper.php b/apps/files_external/lib/Lib/Storage/StreamWrapper.php index 96a306e4f53..8d90161323d 100644 --- a/apps/files_external/lib/Lib/Storage/StreamWrapper.php +++ b/apps/files_external/lib/Lib/Storage/StreamWrapper.php @@ -8,17 +8,13 @@ namespace OCA\Files_External\Lib\Storage; abstract class StreamWrapper extends \OC\Files\Storage\Common { - /** - * @param string $path - * @return string|null - */ - abstract public function constructUrl($path): ?string; + abstract public function constructUrl(string $path): ?string; - public function mkdir($path): bool { + public function mkdir(string $path): bool { return mkdir($this->constructUrl($path)); } - public function rmdir($path): bool { + public function rmdir(string $path): bool { if ($this->is_dir($path) && $this->isDeletable($path)) { $dh = $this->opendir($path); if (!is_resource($dh)) { @@ -40,19 +36,19 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common { } } - public function opendir($path) { + public function opendir(string $path) { return opendir($this->constructUrl($path)); } - public function filetype($path): string|false { + public function filetype(string $path): string|false { return @filetype($this->constructUrl($path)); } - public function file_exists($path): bool { + public function file_exists(string $path): bool { return file_exists($this->constructUrl($path)); } - public function unlink($path): bool { + public function unlink(string $path): bool { $url = $this->constructUrl($path); $success = unlink($url); // normally unlink() is supposed to do this implicitly, @@ -61,11 +57,11 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common { return $success; } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { return fopen($this->constructUrl($path), $mode); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { if ($this->file_exists($path)) { if (is_null($mtime)) { $fh = $this->fopen($path, 'a'); @@ -82,26 +78,19 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common { } } - /** - * @param string $path - * @param string $target - */ - public function getFile($path, $target): bool { + public function getFile(string $path, string $target): bool { return copy($this->constructUrl($path), $target); } - /** - * @param string $target - */ - public function uploadFile($path, $target): bool { + public function uploadFile(string $path, string $target): bool { return copy($path, $this->constructUrl($target)); } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { return rename($this->constructUrl($source), $this->constructUrl($target)); } - public function stat($path): array|false { + public function stat(string $path): array|false { return stat($this->constructUrl($path)); } } diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php index 3582470b3be..0dd6e64bc65 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -70,20 +70,12 @@ class Swift extends \OC\Files\Storage\Common { public const SUBCONTAINER_FILE = '.subcontainers'; - /** - * translate directory path to container name - * - * @param string $path - * @return string - */ - /** * Fetches an object from the API. * If the object is cached already or a * failed "doesn't exist" response was cached, * that one will be returned. * - * @param string $path * @return StorageObject|false object * or false if the object did not exist * @throws \OCP\Files\StorageAuthException @@ -116,13 +108,11 @@ class Swift extends \OC\Files\Storage\Common { /** * Returns whether the given path exists. * - * @param string $path - * * @return bool true if the object exist, false otherwise * @throws \OCP\Files\StorageAuthException * @throws \OCP\Files\StorageNotAvailableException */ - private function doesObjectExist($path): bool { + private function doesObjectExist(string $path): bool { return $this->fetchObject($path) !== false; } @@ -176,7 +166,7 @@ class Swift extends \OC\Files\Storage\Common { $this->mimeDetector = \OC::$server->get(IMimeTypeDetector::class); } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -207,7 +197,7 @@ class Swift extends \OC\Files\Storage\Common { return true; } - public function file_exists($path): bool { + public function file_exists(string $path): bool { $path = $this->normalizePath($path); if ($path !== '.' && $this->is_dir($path)) { @@ -217,7 +207,7 @@ class Swift extends \OC\Files\Storage\Common { return $this->doesObjectExist($path); } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $path = $this->normalizePath($path); if (!$this->is_dir($path) || !$this->isDeletable($path)) { @@ -251,7 +241,7 @@ class Swift extends \OC\Files\Storage\Common { return true; } - public function opendir($path) { + public function opendir(string $path) { $path = $this->normalizePath($path); if ($path === '.') { @@ -287,7 +277,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function stat($path): array|false { + public function stat(string $path): array|false { $path = $this->normalizePath($path); if ($path === '.') { @@ -327,7 +317,7 @@ class Swift extends \OC\Files\Storage\Common { return $stat; } - public function filetype($path) { + public function filetype(string $path) { $path = $this->normalizePath($path); if ($path !== '.' && $this->doesObjectExist($path)) { @@ -343,7 +333,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function unlink($path): bool { + public function unlink(string $path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -367,7 +357,7 @@ class Swift extends \OC\Files\Storage\Common { return true; } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $path = $this->normalizePath($path); switch ($mode) { @@ -417,7 +407,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { $path = $this->normalizePath($path); if (is_null($mtime)) { $mtime = time(); @@ -447,7 +437,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -508,7 +498,7 @@ class Swift extends \OC\Files\Storage\Common { return true; } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -555,7 +545,7 @@ class Swift extends \OC\Files\Storage\Common { return $this->container; } - public function writeBack($tmpFile, $path): void { + public function writeBack(string $tmpFile, string $path): void { $fileData = fopen($tmpFile, 'r'); $this->objectStore->writeObject($path, $fileData, $this->mimeDetector->detectPath($path)); // invalidate target object to force repopulation on fetch @@ -563,7 +553,7 @@ class Swift extends \OC\Files\Storage\Common { unlink($tmpFile); } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { if ($this->is_file($path)) { return parent::hasUpdated($path, $time); } -- 2.39.5