diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index b2d6d24db5eff..be07314311e6a 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -59,11 +59,7 @@ public function __construct($parameters) { $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 @@ private function normalizePath($path): string { 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 @@ private function clearCache(): void { $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 @@ private function headObject(string $key): array|false { * * @throws \Exception */ - private function doesDirectoryExist($path): bool { + private function doesDirectoryExist(string $path): bool { if ($path === '.' || $path === '') { return true; } @@ -185,7 +181,7 @@ private function doesDirectoryExist($path): bool { 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 @@ protected function remove($path): bool { } } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -225,12 +221,12 @@ public function mkdir($path): bool { 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 @@ protected function clearBucket(): bool { 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 @@ private function batchDelete($path = null): bool { 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 @@ public function opendir($path) { } } - 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 @@ public function stat($path): array|false { * 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 @@ private function getContentLength($path): int { * 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 @@ private function getLastModified($path): string { 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 @@ public function is_dir($path): bool { } } - 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 @@ public function filetype($path): string|false { 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 @@ public function getPermissions($path): int { 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 @@ public function unlink($path): bool { return true; } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $path = $this->normalizePath($path); switch ($mode) { @@ -489,7 +485,7 @@ public function fopen($path, $mode) { 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 @@ public function touch($path, $mtime = null): bool { 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 @@ public function copy($source, $target, $isFile = null): bool { 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 @@ public function getId(): string { 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 @@ public static function checkDependencies(): bool { 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 @@ protected function getVersioningStatusFromBucket(): bool { } } - 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 514492156b64f..142fa746184a3 100644 --- a/apps/files_external/lib/Lib/Storage/FTP.php +++ b/apps/files_external/lib/Lib/Storage/FTP.php @@ -82,7 +82,7 @@ public function getId(): string { 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 @@ public static function checkDependencies(): array|bool { } } - 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 @@ public function filemtime($path): int|false { } } - 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 @@ public function filesize($path): false|int|float { } } - 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 @@ public function rmdir($path): bool { } } - /** - * @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 @@ public function test(): bool { } } - public function stat($path): array|false { + public function stat(string $path): array|false { if (!$this->file_exists($path)) { return false; } @@ -187,14 +184,14 @@ public function stat($path): array|false { ]; } - 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 @@ public function unlink($path): bool { } } - 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 @@ public function is_dir($path): bool { } } - 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 @@ public function filetype($path): string|false { } } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $useExisting = true; switch ($mode) { case 'r': @@ -309,7 +306,7 @@ public function readStream(string $path) { 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 @@ public function touch($path, $mtime = null): bool { } } - 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 c8e01a058ff15..e5188db9bccc2 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 @@ public function getUser(): string { 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 @@ private function hostKeysPath(): string|false { 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 @@ protected function readHostKeys(): array { 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 @@ public function mkdir($path): bool { } } - 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 @@ public function rmdir($path): bool { } } - public function opendir($path) { + public function opendir(string $path) { try { $list = $this->getConnection()->nlist($this->absPath($path)); if ($list === false) { @@ -264,7 +261,7 @@ public function opendir($path) { } } - 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 @@ public function filetype($path): string|false { 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 @@ public function file_exists($path): bool { } } - 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 @@ public function unlink($path): bool { } } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { try { $absPath = $this->absPath($path); $connection = $this->getConnection(); @@ -339,7 +336,7 @@ public function fopen($path, $mode) { 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 @@ public function touch($path, $mtime = null): bool { } /** - * @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 @@ public function rename($source, $target): bool { /** * @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 @@ public function stat($path): array|false { } } - /** - * @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 @@ public function constructUrl($path): string { 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 @@ public function writeStream(string $path, $stream, ?int $size = null): int { } } - 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 @@ public function copy($source, $target): bool { } } - 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 @@ public function getPermissions($path): int { } } - 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 e0b4b4002aad4..7dedbd7035a90 100644 --- a/apps/files_external/lib/Lib/Storage/SFTPReadStream.php +++ b/apps/files_external/lib/Lib/Storage/SFTPReadStream.php @@ -44,10 +44,9 @@ public static function register($protocol = 'sftpread') { /** * 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 @@ public function stream_read($count) { 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 a652a83cb836c..d64e89b546217 100644 --- a/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php +++ b/apps/files_external/lib/Lib/Storage/SFTPWriteStream.php @@ -42,10 +42,9 @@ public static function register($protocol = 'sftpwrite') { /** * 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 4f1f51f1bf91f..0b72d62247f88 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -118,7 +118,7 @@ public function __construct($params) { 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, '\\')) { @@ -135,14 +135,11 @@ public function getId(): string { 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) { @@ -153,12 +150,11 @@ protected function relativePath($fullPath): ?string { } /** - * @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; @@ -184,7 +180,6 @@ protected function getFileInfo($path): IFileInfo { } /** - * @param \Exception $e * @throws StorageAuthException */ protected function throwUnavailable(\Exception $e): never { @@ -194,8 +189,6 @@ protected function throwUnavailable(\Exception $e): never { /** * get the acl from fileinfo that is relevant for the configured user - * - * @param IFileInfo $file */ private function getACL(IFileInfo $file): ?ACL { $acls = $file->getAcls(); @@ -210,11 +203,10 @@ private function getACL(IFileInfo $file): ?ACL { } /** - * @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 { @@ -265,10 +257,7 @@ protected function getFolderContents($path): iterable { } } - /** - * @param IFileInfo $info - */ - protected function formatInfo($info): array { + protected function formatInfo(IFileInfo $info): array { $result = [ 'size' => $info->getSize(), 'mtime' => $info->getMTime(), @@ -287,7 +276,7 @@ protected function formatInfo($info): array { * @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; } @@ -326,7 +315,7 @@ public function rename($source, $target, $retry = true): bool { 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) { @@ -368,10 +357,8 @@ private function shareMTime(): int { /** * 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 === '.'; } @@ -382,10 +369,7 @@ private function remoteIsShare(): bool { 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; } @@ -411,11 +395,8 @@ public function unlink($path): bool { /** * 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 @@ -427,11 +408,9 @@ public function hasUpdated($path, $time): bool { } /** - * @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) { @@ -495,7 +474,7 @@ public function fopen($path, $mode) { } } - public function rmdir($path): bool { + public function rmdir(string $path): bool { if ($this->isRootDir($path)) { return false; } @@ -522,7 +501,7 @@ public function rmdir($path): bool { } } - 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)); @@ -538,7 +517,7 @@ public function touch($path, $mtime = null): bool { } } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { try { $fileInfo = $this->getFileInfo($path); } catch (\OCP\Files\NotFoundException $e) { @@ -583,7 +562,7 @@ private function getMetaDataFromFileInfo(IFileInfo $fileInfo): array { return $data; } - public function opendir($path) { + public function opendir(string $path) { try { $files = $this->getFolderContents($path); } catch (NotFoundException $e) { @@ -598,7 +577,7 @@ public function opendir($path) { return IteratorDirectory::wrap($names); } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { try { $files = $this->getFolderContents($directory); foreach ($files as $file) { @@ -611,7 +590,7 @@ public function getDirectoryContent($directory): \Traversable { } } - 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) { @@ -621,7 +600,7 @@ public function filetype($path): string|false { } } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $path = $this->buildPath($path); try { $this->share->mkdir($path); @@ -634,7 +613,7 @@ public function mkdir($path): bool { } } - 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 !== '') { @@ -658,7 +637,7 @@ public function file_exists($path): bool { } } - public function isReadable($path): bool { + public function isReadable(string $path): bool { try { $info = $this->getFileInfo($path); return $this->showHidden || !$info->isHidden(); @@ -669,7 +648,7 @@ public function isReadable($path): bool { } } - 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 @@ -682,7 +661,7 @@ public function isUpdatable($path): bool { } } - 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 @@ public function test(): bool { } } - 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 @@ public function listen($path, callable $callback): void { }); } - 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 96a306e4f53f7..8d90161323d9e 100644 --- a/apps/files_external/lib/Lib/Storage/StreamWrapper.php +++ b/apps/files_external/lib/Lib/Storage/StreamWrapper.php @@ -8,17 +8,13 @@ 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 @@ public function rmdir($path): bool { } } - 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 @@ public function unlink($path): bool { 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 @@ public function touch($path, $mtime = null): bool { } } - /** - * @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 3582470b3be5e..0dd6e64bc65cb 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -70,20 +70,12 @@ private function normalizePath(string $path): string { 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 @@ private function fetchObject(string $path): StorageObject|false { /** * 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 @@ public function __construct($params) { $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 @@ public function mkdir($path): bool { 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 @@ public function file_exists($path): bool { 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 @@ public function rmdir($path): bool { return true; } - public function opendir($path) { + public function opendir(string $path) { $path = $this->normalizePath($path); if ($path === '.') { @@ -287,7 +277,7 @@ public function opendir($path) { } } - public function stat($path): array|false { + public function stat(string $path): array|false { $path = $this->normalizePath($path); if ($path === '.') { @@ -327,7 +317,7 @@ public function stat($path): array|false { return $stat; } - public function filetype($path) { + public function filetype(string $path) { $path = $this->normalizePath($path); if ($path !== '.' && $this->doesObjectExist($path)) { @@ -343,7 +333,7 @@ public function filetype($path) { } } - public function unlink($path): bool { + public function unlink(string $path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -367,7 +357,7 @@ public function unlink($path): bool { return true; } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $path = $this->normalizePath($path); switch ($mode) { @@ -417,7 +407,7 @@ public function fopen($path, $mode) { } } - 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 @@ public function touch($path, $mtime = null): bool { } } - 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 @@ public function copy($source, $target): bool { 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 @@ public function getContainer(): Container { 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 @@ public function writeBack($tmpFile, $path): void { 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); }