diff options
author | Kate <26026535+provokateurin@users.noreply.github.com> | 2024-09-27 07:40:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-27 07:40:05 +0200 |
commit | 4f88123d2ba649fb6fe2df3d069a297c101dd019 (patch) | |
tree | ed1cd250ce4edc6a6aae09b13f0f631947185d63 /apps | |
parent | 7887ab8cfa6c20e582a9f3b8b5fecce0201e8e43 (diff) | |
parent | 227609a95412644087522d7762de7c6683cbc35c (diff) | |
download | nextcloud-server-4f88123d2ba649fb6fe2df3d069a297c101dd019.tar.gz nextcloud-server-4f88123d2ba649fb6fe2df3d069a297c101dd019.zip |
Merge pull request #48219 from nextcloud/fix/istorage/return-types
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php | 4 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/AmazonS3.php | 75 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/FTP.php | 31 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/OwnCloud.php | 2 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SFTP.php | 107 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/SMB.php | 80 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/StreamWrapper.php | 22 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/Storage/Swift.php | 45 | ||||
-rw-r--r-- | apps/files_sharing/lib/External/Storage.php | 34 | ||||
-rw-r--r-- | apps/files_sharing/lib/SharedStorage.php | 63 | ||||
-rw-r--r-- | apps/files_sharing/tests/ExternalStorageTest.php | 7 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Storage.php | 32 | ||||
-rw-r--r-- | apps/files_trashbin/tests/StorageTest.php | 4 | ||||
-rw-r--r-- | apps/workflowengine/tests/Check/FileMimeTypeTest.php | 2 |
14 files changed, 178 insertions, 330 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php index fb180b7c65d..2e19aec95e8 100644 --- a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php @@ -283,8 +283,8 @@ class DirectoryTest extends \Test\TestCase { $storage->expects($this->any()) ->method('instanceOfStorage') ->willReturnMap([ - '\OCA\Files_Sharing\SharedStorage' => false, - '\OC\Files\Storage\Wrapper\Quota' => false, + ['\OCA\Files_Sharing\SharedStorage', false], + ['\OC\Files\Storage\Wrapper\Quota', false], ]); $storage->expects($this->once()) diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 5325b25a66b..b2d6d24db5e 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -28,7 +28,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { private LoggerInterface $logger; - public function needsPartFile() { + public function needsPartFile(): bool { return false; } @@ -63,7 +63,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { * @param string $path * @return string correctly encoded path */ - private function normalizePath($path) { + private function normalizePath($path): string { $path = trim($path, '/'); if (!$path) { @@ -73,24 +73,24 @@ class AmazonS3 extends \OC\Files\Storage\Common { return $path; } - private function isRoot($path) { + private function isRoot($path): bool { return $path === '.'; } - private function cleanKey($path) { + private function cleanKey($path): string { if ($this->isRoot($path)) { return '/'; } return $path; } - private function clearCache() { + private function clearCache(): void { $this->objectCache = new CappedMemoryCache(); $this->directoryCache = new CappedMemoryCache(); $this->filesCache = new CappedMemoryCache(); } - private function invalidateCache($key) { + private function invalidateCache($key): void { unset($this->objectCache[$key]); $keys = array_keys($this->objectCache->getData()); $keyLength = strlen($key); @@ -110,10 +110,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { unset($this->directoryCache[$key]); } - /** - * @return array|false - */ - private function headObject(string $key) { + private function headObject(string $key): array|false { if (!isset($this->objectCache[$key])) { try { $this->objectCache[$key] = $this->getConnection()->headObject([ @@ -144,11 +141,9 @@ class AmazonS3 extends \OC\Files\Storage\Common { * Implementation from flysystem-aws-s3-v3: * https://github.com/thephpleague/flysystem-aws-s3-v3/blob/8241e9cc5b28f981e0d24cdaf9867f14c7498ae4/src/AwsS3Adapter.php#L670-L694 * - * @param $path - * @return bool * @throws \Exception */ - private function doesDirectoryExist($path) { + private function doesDirectoryExist($path): bool { if ($path === '.' || $path === '') { return true; } @@ -190,13 +185,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return false; } - /** - * Remove a file or folder - * - * @param string $path - * @return bool - */ - protected function remove($path) { + protected function remove($path): bool { // remember fileType to reduce http calls $fileType = $this->filetype($path); if ($fileType === 'dir') { @@ -208,7 +197,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } } - public function mkdir($path) { + public function mkdir($path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -236,12 +225,12 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function file_exists($path) { + public function file_exists($path): bool { return $this->filetype($path) !== false; } - public function rmdir($path) { + public function rmdir($path): bool { $path = $this->normalizePath($path); if ($this->isRoot($path)) { @@ -256,12 +245,12 @@ class AmazonS3 extends \OC\Files\Storage\Common { return $this->batchDelete($path); } - protected function clearBucket() { + protected function clearBucket(): bool { $this->clearCache(); return $this->batchDelete(); } - private function batchDelete($path = null) { + private function batchDelete($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 @@ -312,7 +301,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } } - public function stat($path) { + public function stat($path): array|false { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -334,11 +323,8 @@ 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. - * - * @param $path - * @return int|mixed */ - private function getContentLength($path) { + private function getContentLength($path): int { if (isset($this->filesCache[$path])) { return (int)$this->filesCache[$path]['ContentLength']; } @@ -356,11 +342,8 @@ 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. - * - * @param $path - * @return mixed|string */ - private function getLastModified($path) { + private function getLastModified($path): string { if (isset($this->filesCache[$path])) { return $this->filesCache[$path]['LastModified']; } @@ -373,7 +356,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return 'now'; } - public function is_dir($path) { + public function is_dir($path): bool { $path = $this->normalizePath($path); if (isset($this->filesCache[$path])) { @@ -391,7 +374,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } } - public function filetype($path) { + public function filetype($path): string|false { $path = $this->normalizePath($path); if ($this->isRoot($path)) { @@ -419,7 +402,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return false; } - public function getPermissions($path) { + public function getPermissions($path): int { $type = $this->filetype($path); if (!$type) { return 0; @@ -427,7 +410,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return $type === 'dir' ? Constants::PERMISSION_ALL : Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE; } - public function unlink($path) { + public function unlink($path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -506,7 +489,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return false; } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { if (is_null($mtime)) { $mtime = time(); } @@ -541,7 +524,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function copy($source, $target, $isFile = null) { + public function copy($source, $target, $isFile = null): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -584,7 +567,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function rename($source, $target) { + public function rename($source, $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -611,18 +594,18 @@ class AmazonS3 extends \OC\Files\Storage\Common { return true; } - public function test() { + public function test(): bool { $this->getConnection()->headBucket([ 'Bucket' => $this->bucket ]); return true; } - public function getId() { + public function getId(): string { return $this->id; } - public function writeBack($tmpFile, $path) { + public function writeBack($tmpFile, $path): bool { try { $source = fopen($tmpFile, 'r'); $this->writeObject($path, $source, $this->mimeDetector->detectPath($path)); @@ -642,7 +625,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { /** * check if curl is installed */ - public static function checkDependencies() { + public static function checkDependencies(): bool { return true; } @@ -743,7 +726,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { } } - public function hasUpdated($path, $time) { + public function hasUpdated($path, $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 a7a348cbf43..514492156b6 100644 --- a/apps/files_external/lib/Lib/Storage/FTP.php +++ b/apps/files_external/lib/Lib/Storage/FTP.php @@ -78,15 +78,15 @@ class FTP extends Common { return $this->connection; } - public function getId() { + public function getId(): string { return 'ftp::' . $this->username . '@' . $this->host . '/' . $this->root; } - protected function buildPath($path) { + protected function buildPath($path): string { return rtrim($this->root . '/' . $path, '/'); } - public static function checkDependencies() { + public static function checkDependencies(): array|bool { if (function_exists('ftp_login')) { return true; } else { @@ -94,7 +94,7 @@ class FTP extends Common { } } - public function filemtime($path) { + public function filemtime($path): int|false { $result = $this->getConnection()->mdtm($this->buildPath($path)); if ($result === -1) { @@ -135,7 +135,7 @@ class FTP extends Common { } } - public function rmdir($path) { + public function rmdir($path): bool { if ($this->is_dir($path)) { $result = $this->getConnection()->rmdir($this->buildPath($path)); // recursive rmdir support depends on the ftp server @@ -153,7 +153,6 @@ class FTP extends Common { /** * @param string $path - * @return bool */ private function recursiveRmDir($path): bool { $contents = $this->getDirectoryContent($path); @@ -170,7 +169,7 @@ class FTP extends Common { return $result; } - public function test() { + public function test(): bool { try { return $this->getConnection()->systype() !== false; } catch (\Exception $e) { @@ -178,7 +177,7 @@ class FTP extends Common { } } - public function stat($path) { + public function stat($path): array|false { if (!$this->file_exists($path)) { return false; } @@ -188,14 +187,14 @@ class FTP extends Common { ]; } - public function file_exists($path) { + public function file_exists($path): bool { if ($path === '' || $path === '.' || $path === '/') { return true; } return $this->filetype($path) !== false; } - public function unlink($path) { + public function unlink($path): bool { switch ($this->filetype($path)) { case 'dir': return $this->rmdir($path); @@ -211,14 +210,14 @@ class FTP extends Common { return IteratorDirectory::wrap($files); } - public function mkdir($path) { + public function mkdir($path): bool { if ($this->is_dir($path)) { return false; } return $this->getConnection()->mkdir($this->buildPath($path)) !== false; } - public function is_dir($path) { + public function is_dir($path): bool { if ($path === '') { return true; } @@ -230,11 +229,11 @@ class FTP extends Common { } } - public function is_file($path) { + public function is_file($path): bool { return $this->filesize($path) !== false; } - public function filetype($path) { + public function filetype($path): string|false { if ($this->is_dir($path)) { return 'dir'; } elseif ($this->is_file($path)) { @@ -310,7 +309,7 @@ class FTP extends Common { return $stream; } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { if ($this->file_exists($path)) { return false; } else { @@ -319,7 +318,7 @@ class FTP extends Common { } } - public function rename($source, $target) { + public function rename($source, $target): bool { $this->unlink($target); return $this->getConnection()->rename($this->buildPath($source), $this->buildPath($target)); } diff --git a/apps/files_external/lib/Lib/Storage/OwnCloud.php b/apps/files_external/lib/Lib/Storage/OwnCloud.php index fb5c7207486..5de708afb04 100644 --- a/apps/files_external/lib/Lib/Storage/OwnCloud.php +++ b/apps/files_external/lib/Lib/Storage/OwnCloud.php @@ -55,7 +55,7 @@ class OwnCloud extends \OC\Files\Storage\DAV implements IDisableEncryptionStorag parent::__construct($params); } - public function needsPartFile() { + public function needsPartFile(): bool { return false; } } diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php index a6a28245214..c8e01a058ff 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) { + private function splitHost($host): array { $input = $host; if (!str_contains($host, '://')) { // add a protocol to fix parse_url behavior with ipv6 @@ -56,9 +56,6 @@ class SFTP extends Common { } } - /** - * {@inheritdoc} - */ public function __construct($params) { // Register sftp:// Stream::register(); @@ -98,7 +95,7 @@ class SFTP extends Common { * @return \phpseclib\Net\SFTP connected client instance * @throws \Exception when the connection failed */ - public function getConnection() { + public function getConnection(): \phpseclib\Net\SFTP { if (!is_null($this->client)) { return $this->client; } @@ -132,10 +129,7 @@ class SFTP extends Common { return $this->client; } - /** - * {@inheritdoc} - */ - public function test() { + public function test(): bool { if ( !isset($this->host) || !isset($this->user) @@ -145,10 +139,7 @@ class SFTP extends Common { return $this->getConnection()->nlist() !== false; } - /** - * {@inheritdoc} - */ - public function getId() { + public function getId(): string { $id = 'sftp::' . $this->user . '@' . $this->host; if ($this->port !== 22) { $id .= ':' . $this->port; @@ -160,39 +151,26 @@ class SFTP extends Common { return $id; } - /** - * @return string - */ - public function getHost() { + public function getHost(): string { return $this->host; } - /** - * @return string - */ - public function getRoot() { + public function getRoot(): string { return $this->root; } - /** - * @return mixed - */ - public function getUser() { + public function getUser(): string { return $this->user; } /** * @param string $path - * @return string */ - private function absPath($path) { + private function absPath($path): string { return $this->root . $this->cleanPath($path); } - /** - * @return string|false - */ - private function hostKeysPath() { + private function hostKeysPath(): string|false { try { $userId = \OC_User::getUser(); if ($userId === false) { @@ -207,11 +185,7 @@ class SFTP extends Common { return false; } - /** - * @param $keys - * @return bool - */ - protected function writeHostKeys($keys) { + protected function writeHostKeys($keys): bool { try { $keyPath = $this->hostKeysPath(); if ($keyPath && file_exists($keyPath)) { @@ -227,10 +201,7 @@ class SFTP extends Common { return false; } - /** - * @return array - */ - protected function readHostKeys() { + protected function readHostKeys(): array { try { $keyPath = $this->hostKeysPath(); if (file_exists($keyPath)) { @@ -253,10 +224,7 @@ class SFTP extends Common { return []; } - /** - * {@inheritdoc} - */ - public function mkdir($path) { + public function mkdir($path): bool { try { return $this->getConnection()->mkdir($this->absPath($path)); } catch (\Exception $e) { @@ -264,10 +232,7 @@ class SFTP extends Common { } } - /** - * {@inheritdoc} - */ - public function rmdir($path) { + public function rmdir($path): bool { try { $result = $this->getConnection()->delete($this->absPath($path), true); // workaround: stray stat cache entry when deleting empty folders @@ -279,9 +244,6 @@ class SFTP extends Common { } } - /** - * {@inheritdoc} - */ public function opendir($path) { try { $list = $this->getConnection()->nlist($this->absPath($path)); @@ -302,10 +264,7 @@ class SFTP extends Common { } } - /** - * {@inheritdoc} - */ - public function filetype($path) { + public function filetype($path): string|false { try { $stat = $this->getConnection()->stat($this->absPath($path)); if (!is_array($stat) || !array_key_exists('type', $stat)) { @@ -323,10 +282,7 @@ class SFTP extends Common { return false; } - /** - * {@inheritdoc} - */ - public function file_exists($path) { + public function file_exists($path): bool { try { return $this->getConnection()->stat($this->absPath($path)) !== false; } catch (\Exception $e) { @@ -334,10 +290,7 @@ class SFTP extends Common { } } - /** - * {@inheritdoc} - */ - public function unlink($path) { + public function unlink($path): bool { try { return $this->getConnection()->delete($this->absPath($path), true); } catch (\Exception $e) { @@ -345,9 +298,6 @@ class SFTP extends Common { } } - /** - * {@inheritdoc} - */ public function fopen($path, $mode) { try { $absPath = $this->absPath($path); @@ -389,10 +339,7 @@ class SFTP extends Common { return false; } - /** - * {@inheritdoc} - */ - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { try { if (!is_null($mtime)) { return false; @@ -413,14 +360,11 @@ class SFTP extends Common { * @param string $target * @throws \Exception */ - public function getFile($path, $target) { + public function getFile($path, $target): void { $this->getConnection()->get($path, $target); } - /** - * {@inheritdoc} - */ - public function rename($source, $target) { + public function rename($source, $target): bool { try { if ($this->file_exists($target)) { $this->unlink($target); @@ -437,7 +381,7 @@ class SFTP extends Common { /** * @return array{mtime: int, size: int, ctime: int}|false */ - public function stat($path) { + public function stat($path): array|false { try { $stat = $this->getConnection()->stat($this->absPath($path)); @@ -456,9 +400,8 @@ class SFTP extends Common { /** * @param string $path - * @return string */ - public function constructUrl($path) { + public function constructUrl($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). @@ -466,7 +409,7 @@ class SFTP extends Common { return $url; } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): int|float|false { /** @psalm-suppress InternalMethod */ $result = $this->getConnection()->put($this->absPath($path), $data); if ($result) { @@ -498,7 +441,7 @@ class SFTP extends Common { } } - public function copy($source, $target) { + public function copy($source, $target): bool { if ($this->is_dir($source) || $this->is_dir($target)) { return parent::copy($source, $target); } else { @@ -525,7 +468,7 @@ class SFTP extends Common { } } - public function getPermissions($path) { + public function getPermissions($path): int { $stat = $this->getConnection()->stat($this->absPath($path)); if (!$stat) { return 0; @@ -537,7 +480,7 @@ class SFTP extends Common { } } - public function getMetaData($path) { + public function getMetaData($path): ?array { $stat = $this->getConnection()->stat($this->absPath($path)); if (!$stat) { return null; diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 91a6eab8d09..4f1f51f1bf9 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -118,7 +118,7 @@ class SMB extends Common implements INotifyStorage { parent::__construct($params); } - private function splitUser($user) { + private function splitUser($user): array { if (str_contains($user, '/')) { return explode('/', $user, 2); } elseif (str_contains($user, '\\')) { @@ -128,10 +128,7 @@ class SMB extends Common implements INotifyStorage { return [null, $user]; } - /** - * @return string - */ - public function getId() { + public function getId(): string { // FIXME: double slash to keep compatible with the old storage ids, // failure to do so will lead to creation of a new storage id and // loss of shares from the storage @@ -140,13 +137,12 @@ class SMB extends Common implements INotifyStorage { /** * @param string $path - * @return string */ - protected function buildPath($path) { + protected function buildPath($path): string { return Filesystem::normalizePath($this->root . '/' . $path, true, false, true); } - protected function relativePath($fullPath) { + protected function relativePath($fullPath): ?string { if ($fullPath === $this->root) { return ''; } elseif (substr($fullPath, 0, strlen($this->root)) === $this->root) { @@ -158,12 +154,11 @@ class SMB extends Common implements INotifyStorage { /** * @param string $path - * @return IFileInfo * @throws StorageAuthException * @throws \OCP\Files\NotFoundException * @throws \OCP\Files\ForbiddenException */ - protected function getFileInfo($path) { + protected function getFileInfo($path): IFileInfo { try { $path = $this->buildPath($path); $cached = $this->statCache[$path] ?? null; @@ -190,10 +185,9 @@ class SMB extends Common implements INotifyStorage { /** * @param \Exception $e - * @return never * @throws StorageAuthException */ - protected function throwUnavailable(\Exception $e) { + protected function throwUnavailable(\Exception $e): never { $this->logger->error('Error while getting file info', ['exception' => $e]); throw new StorageAuthException($e->getMessage(), $e); } @@ -202,7 +196,6 @@ class SMB extends Common implements INotifyStorage { * get the acl from fileinfo that is relevant for the configured user * * @param IFileInfo $file - * @return ACL|null */ private function getACL(IFileInfo $file): ?ACL { $acls = $file->getAcls(); @@ -274,9 +267,8 @@ class SMB extends Common implements INotifyStorage { /** * @param IFileInfo $info - * @return array */ - protected function formatInfo($info) { + protected function formatInfo($info): array { $result = [ 'size' => $info->getSize(), 'mtime' => $info->getMTime(), @@ -294,7 +286,6 @@ class SMB extends Common implements INotifyStorage { * * @param string $source the old name of the path * @param string $target the new name of the path - * @return bool true if the rename is successful, false otherwise */ public function rename($source, $target, $retry = true): bool { if ($this->isRootDir($source) || $this->isRootDir($target)) { @@ -335,7 +326,7 @@ class SMB extends Common implements INotifyStorage { return $result; } - public function stat($path, $retry = true) { + public function stat($path, $retry = true): array|false { try { $result = $this->formatInfo($this->getFileInfo($path)); } catch (\OCP\Files\ForbiddenException $e) { @@ -357,10 +348,8 @@ class SMB extends Common implements INotifyStorage { /** * get the best guess for the modification time of the share - * - * @return int */ - private function shareMTime() { + private function shareMTime(): int { $highestMTime = 0; $files = $this->share->dir($this->root); foreach ($files as $fileInfo) { @@ -381,26 +370,22 @@ class SMB extends Common implements INotifyStorage { * Check if the path is our root dir (not the smb one) * * @param string $path the path - * @return bool */ - private function isRootDir($path) { + private function isRootDir($path): bool { return $path === '' || $path === '/' || $path === '.'; } /** * Check if our root points to a smb share - * - * @return bool true if our root points to a share false otherwise */ - private function remoteIsShare() { + private function remoteIsShare(): bool { return $this->share->getName() && (!$this->root || $this->root === '/'); } /** * @param string $path - * @return bool */ - public function unlink($path) { + public function unlink($path): bool { if ($this->isRootDir($path)) { return false; } @@ -429,9 +414,8 @@ class SMB extends Common implements INotifyStorage { * * @param string $path * @param int $time - * @return bool */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $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 @@ -445,7 +429,7 @@ class SMB extends Common implements INotifyStorage { /** * @param string $path * @param string $mode - * @return resource|bool + * @return resource|false */ public function fopen($path, $mode) { $fullPath = $this->buildPath($path); @@ -511,7 +495,7 @@ class SMB extends Common implements INotifyStorage { } } - public function rmdir($path) { + public function rmdir($path): bool { if ($this->isRootDir($path)) { return false; } @@ -538,7 +522,7 @@ class SMB extends Common implements INotifyStorage { } } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { try { if (!$this->file_exists($path)) { $fh = $this->share->write($this->buildPath($path)); @@ -554,7 +538,7 @@ class SMB extends Common implements INotifyStorage { } } - public function getMetaData($path) { + public function getMetaData($path): ?array { try { $fileInfo = $this->getFileInfo($path); } catch (\OCP\Files\NotFoundException $e) { @@ -562,14 +546,11 @@ class SMB extends Common implements INotifyStorage { } catch (\OCP\Files\ForbiddenException $e) { return null; } - if (!$fileInfo) { - return null; - } return $this->getMetaDataFromFileInfo($fileInfo); } - private function getMetaDataFromFileInfo(IFileInfo $fileInfo) { + private function getMetaDataFromFileInfo(IFileInfo $fileInfo): array { $permissions = Constants::PERMISSION_READ + Constants::PERMISSION_SHARE; if ( @@ -630,7 +611,7 @@ class SMB extends Common implements INotifyStorage { } } - public function filetype($path) { + public function filetype($path): string|false { try { return $this->getFileInfo($path)->isDirectory() ? 'dir' : 'file'; } catch (\OCP\Files\NotFoundException $e) { @@ -640,7 +621,7 @@ class SMB extends Common implements INotifyStorage { } } - public function mkdir($path) { + public function mkdir($path): bool { $path = $this->buildPath($path); try { $this->share->mkdir($path); @@ -653,7 +634,7 @@ class SMB extends Common implements INotifyStorage { } } - public function file_exists($path) { + public function file_exists($path): bool { try { // Case sensitive filesystem doesn't matter for root directory if ($this->caseSensitive === false && $path !== '') { @@ -677,7 +658,7 @@ class SMB extends Common implements INotifyStorage { } } - public function isReadable($path) { + public function isReadable($path): bool { try { $info = $this->getFileInfo($path); return $this->showHidden || !$info->isHidden(); @@ -688,7 +669,7 @@ class SMB extends Common implements INotifyStorage { } } - public function isUpdatable($path) { + public function isUpdatable($path): bool { try { $info = $this->getFileInfo($path); // following windows behaviour for read-only folders: they can be written into @@ -701,7 +682,7 @@ class SMB extends Common implements INotifyStorage { } } - public function isDeletable($path) { + public function isDeletable($path): bool { try { $info = $this->getFileInfo($path); return ($this->showHidden || !$info->isHidden()) && !$info->isReadOnly(); @@ -715,19 +696,14 @@ class SMB extends Common implements INotifyStorage { /** * check if smbclient is installed */ - public static function checkDependencies() { + public static function checkDependencies(): array|bool { return ( (bool)\OC_Helper::findBinaryPath('smbclient') || NativeServer::available(new System()) ) ? true : ['smbclient']; } - /** - * Test a storage for availability - * - * @return bool - */ - public function test() { + public function test(): bool { try { return parent::test(); } catch (StorageAuthException $e) { @@ -740,7 +716,7 @@ class SMB extends Common implements INotifyStorage { } } - public function listen($path, callable $callback) { + public function listen($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()); @@ -750,7 +726,7 @@ class SMB extends Common implements INotifyStorage { }); } - public function notify($path) { + public function notify($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 2928c081505..96a306e4f53 100644 --- a/apps/files_external/lib/Lib/Storage/StreamWrapper.php +++ b/apps/files_external/lib/Lib/Storage/StreamWrapper.php @@ -12,13 +12,13 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common { * @param string $path * @return string|null */ - abstract public function constructUrl($path); + abstract public function constructUrl($path): ?string; - public function mkdir($path) { + public function mkdir($path): bool { return mkdir($this->constructUrl($path)); } - public function rmdir($path) { + public function rmdir($path): bool { if ($this->is_dir($path) && $this->isDeletable($path)) { $dh = $this->opendir($path); if (!is_resource($dh)) { @@ -44,15 +44,15 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common { return opendir($this->constructUrl($path)); } - public function filetype($path) { + public function filetype($path): string|false { return @filetype($this->constructUrl($path)); } - public function file_exists($path) { + public function file_exists($path): bool { return file_exists($this->constructUrl($path)); } - public function unlink($path) { + public function unlink($path): bool { $url = $this->constructUrl($path); $success = unlink($url); // normally unlink() is supposed to do this implicitly, @@ -65,7 +65,7 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common { return fopen($this->constructUrl($path), $mode); } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { if ($this->file_exists($path)) { if (is_null($mtime)) { $fh = $this->fopen($path, 'a'); @@ -86,22 +86,22 @@ abstract class StreamWrapper extends \OC\Files\Storage\Common { * @param string $path * @param string $target */ - public function getFile($path, $target) { + public function getFile($path, $target): bool { return copy($this->constructUrl($path), $target); } /** * @param string $target */ - public function uploadFile($path, $target) { + public function uploadFile($path, $target): bool { return copy($path, $this->constructUrl($target)); } - public function rename($source, $target) { + public function rename($source, $target): bool { return rename($this->constructUrl($source), $this->constructUrl($target)); } - public function stat($path) { + public function stat($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 9aabf5b56b4..3582470b3be 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -16,6 +16,7 @@ use OC\Files\ObjectStore\SwiftFactory; use OCP\Files\IMimeTypeDetector; use OCP\Files\StorageBadConfigException; use OpenStack\Common\Error\BadResponseError; +use OpenStack\ObjectStore\v1\Models\Container; use OpenStack\ObjectStore\v1\Models\StorageObject; use Psr\Log\LoggerInterface; @@ -23,7 +24,7 @@ class Swift extends \OC\Files\Storage\Common { /** @var SwiftFactory */ private $connectionFactory; /** - * @var \OpenStack\ObjectStore\v1\Models\Container + * @var Container */ private $container; /** @@ -55,11 +56,7 @@ class Swift extends \OC\Files\Storage\Common { */ private $objectCache; - /** - * @param string $path - * @return mixed|string - */ - private function normalizePath(string $path) { + private function normalizePath(string $path): string { $path = trim($path, '/'); if (!$path) { @@ -87,12 +84,12 @@ class Swift extends \OC\Files\Storage\Common { * that one will be returned. * * @param string $path - * @return StorageObject|bool object - * or false if the object did not exist + * @return StorageObject|false object + * or false if the object did not exist * @throws \OCP\Files\StorageAuthException * @throws \OCP\Files\StorageNotAvailableException */ - private function fetchObject(string $path) { + private function fetchObject(string $path): StorageObject|false { $cached = $this->objectCache->get($path); if ($cached !== null) { // might be "false" if object did not exist from last check @@ -125,7 +122,7 @@ class Swift extends \OC\Files\Storage\Common { * @throws \OCP\Files\StorageAuthException * @throws \OCP\Files\StorageNotAvailableException */ - private function doesObjectExist($path) { + private function doesObjectExist($path): bool { return $this->fetchObject($path) !== false; } @@ -179,7 +176,7 @@ class Swift extends \OC\Files\Storage\Common { $this->mimeDetector = \OC::$server->get(IMimeTypeDetector::class); } - public function mkdir($path) { + public function mkdir($path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -210,7 +207,7 @@ class Swift extends \OC\Files\Storage\Common { return true; } - public function file_exists($path) { + public function file_exists($path): bool { $path = $this->normalizePath($path); if ($path !== '.' && $this->is_dir($path)) { @@ -220,7 +217,7 @@ class Swift extends \OC\Files\Storage\Common { return $this->doesObjectExist($path); } - public function rmdir($path) { + public function rmdir($path): bool { $path = $this->normalizePath($path); if (!$this->is_dir($path) || !$this->isDeletable($path)) { @@ -290,7 +287,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function stat($path) { + public function stat($path): array|false { $path = $this->normalizePath($path); if ($path === '.') { @@ -346,7 +343,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function unlink($path) { + public function unlink($path): bool { $path = $this->normalizePath($path); if ($this->is_dir($path)) { @@ -420,7 +417,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { $path = $this->normalizePath($path); if (is_null($mtime)) { $mtime = time(); @@ -450,7 +447,7 @@ class Swift extends \OC\Files\Storage\Common { } } - public function copy($source, $target) { + public function copy($source, $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -511,7 +508,7 @@ class Swift extends \OC\Files\Storage\Common { return true; } - public function rename($source, $target) { + public function rename($source, $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); @@ -536,18 +533,18 @@ class Swift extends \OC\Files\Storage\Common { return false; } - public function getId() { + public function getId(): string { return $this->id; } /** * Returns the initialized object store container. * - * @return \OpenStack\ObjectStore\v1\Models\Container + * @return Container * @throws \OCP\Files\StorageAuthException * @throws \OCP\Files\StorageNotAvailableException */ - public function getContainer() { + public function getContainer(): Container { if (is_null($this->container)) { $this->container = $this->connectionFactory->getContainer(); @@ -558,7 +555,7 @@ class Swift extends \OC\Files\Storage\Common { return $this->container; } - public function writeBack($tmpFile, $path) { + public function writeBack($tmpFile, $path): void { $fileData = fopen($tmpFile, 'r'); $this->objectStore->writeObject($path, $fileData, $this->mimeDetector->detectPath($path)); // invalidate target object to force repopulation on fetch @@ -566,7 +563,7 @@ class Swift extends \OC\Files\Storage\Common { unlink($tmpFile); } - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { if ($this->is_file($path)) { return parent::hasUpdated($path, $time); } @@ -591,7 +588,7 @@ class Swift extends \OC\Files\Storage\Common { /** * check if curl is installed */ - public static function checkDependencies() { + public static function checkDependencies(): bool { return true; } } diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php index 6e5e219ae69..718afbf7499 100644 --- a/apps/files_sharing/lib/External/Storage.php +++ b/apps/files_sharing/lib/External/Storage.php @@ -18,6 +18,9 @@ use OCA\Files_Sharing\ISharedStorage; use OCP\AppFramework\Http; use OCP\Constants; use OCP\Federation\ICloudId; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IWatcher; use OCP\Files\NotFoundException; use OCP\Files\Storage\IDisableEncryptionStorage; use OCP\Files\Storage\IReliableEtagStorage; @@ -91,7 +94,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, ); } - public function getWatcher($path = '', $storage = null) { + public function getWatcher($path = '', $storage = null): IWatcher { if (!$storage) { $storage = $this; } @@ -122,22 +125,18 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, return $this->password; } - /** - * Get id of the mount point. - * @return string - */ - public function getId() { + public function getId(): string { return 'shared::' . md5($this->token . '@' . $this->getRemote()); } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { if (is_null($this->cache)) { $this->cache = new Cache($this, $this->cloudId); } return $this->cache; } - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -148,16 +147,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, return $this->scanner; } - /** - * Check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @throws \OCP\Files\StorageNotAvailableException - * @throws \OCP\Files\StorageInvalidException - * @return bool - */ - public function hasUpdated($path, $time) { + public function hasUpdated($path, $time): bool { // since for owncloud webdav servers we can rely on etag propagation we only need to check the root of the storage // because of that we only do one check for the entire storage per request if ($this->updateChecked) { @@ -177,7 +167,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, } } - public function test() { + public function test(): bool { try { return parent::test(); } catch (StorageInvalidException $e) { @@ -227,7 +217,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, } } - public function file_exists($path) { + public function file_exists($path): bool { if ($path === '') { return true; } else { @@ -368,7 +358,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, return $permissions; } - public function needsPartFile() { + public function needsPartFile(): bool { return false; } @@ -418,7 +408,7 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, return $permissions; } - public function free_space($path) { + public function free_space($path): int|float|false { return parent::free_space(''); } diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 0a6a068c441..7addc9f0a91 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -9,18 +9,21 @@ namespace OCA\Files_Sharing; use OC\Files\Cache\CacheDependencies; use OC\Files\Cache\FailedCache; use OC\Files\Cache\NullWatcher; -use OC\Files\Cache\Watcher; use OC\Files\ObjectStore\HomeObjectStoreStorage; use OC\Files\Storage\Common; use OC\Files\Storage\FailedStorage; use OC\Files\Storage\Home; +use OC\Files\Storage\Storage; use OC\Files\Storage\Wrapper\PermissionsMask; use OC\Files\Storage\Wrapper\Wrapper; use OC\User\NoUserException; use OCA\Files_External\Config\ConfigAdapter; use OCA\Files_Sharing\ISharedStorage as LegacyISharedStorage; use OCP\Constants; +use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IWatcher; use OCP\Files\Config\IUserMountCache; use OCP\Files\Folder; use OCP\Files\IHomeStorage; @@ -78,7 +81,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha /** * @psalm-suppress NonInvariantDocblockPropertyType - * @var ?\OC\Files\Storage\Storage $storage + * @var ?Storage $storage */ protected $storage; @@ -118,7 +121,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha } /** - * @psalm-assert \OC\Files\Storage\Storage $this->storage + * @psalm-assert Storage $this->storage */ private function init() { if ($this->initialized) { @@ -199,9 +202,6 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha self::$initDepth--; } - /** - * @inheritdoc - */ public function instanceOfStorage($class): bool { if ($class === '\OC\Files\Storage\Common' || $class == Common::class) { return true; @@ -230,21 +230,10 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->getSourceRootInfo() && ($this->getSourceRootInfo()->getPermissions() & Constants::PERMISSION_SHARE) === Constants::PERMISSION_SHARE; } - /** - * get id of the mount point - * - * @return string - */ public function getId(): string { return 'shared::' . $this->getMountPoint(); } - /** - * Get the permissions granted for a shared file - * - * @param string $path Shared target file path - * @return int CRUDS permissions granted - */ public function getPermissions($path = ''): int { if (!$this->isValid()) { return 0; @@ -347,13 +336,6 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->nonMaskedStorage->fopen($this->getUnjailedPath($path), $mode); } - /** - * see https://www.php.net/manual/en/function.rename.php - * - * @param string $source - * @param string $target - * @return bool - */ public function rename($source, $target): bool { $this->init(); $isPartFile = pathinfo($source, PATHINFO_EXTENSION) === 'part'; @@ -402,9 +384,6 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->superShare->getShareOwner(); } - /** - * @return \OCP\Share\IShare - */ public function getShare(): IShare { return $this->superShare; } @@ -418,7 +397,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->superShare->getNodeType(); } - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { if ($this->cache) { return $this->cache; } @@ -439,7 +418,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->cache; } - public function getScanner($path = '', $storage = null) { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -450,7 +429,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->superShare->getShareOwner(); } - public function getWatcher($path = '', $storage = null): Watcher { + public function getWatcher($path = '', $storage = null): IWatcher { if ($this->watcher) { return $this->watcher; } @@ -488,7 +467,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return true; } - public function acquireLock($path, $type, ILockingProvider $provider) { + public function acquireLock($path, $type, ILockingProvider $provider): void { /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->acquireLock($targetInternalPath, $type, $provider); @@ -499,7 +478,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha } } - public function releaseLock($path, $type, ILockingProvider $provider) { + public function releaseLock($path, $type, ILockingProvider $provider): void { /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->releaseLock($targetInternalPath, $type, $provider); @@ -510,16 +489,13 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha } } - public function changeLock($path, $type, ILockingProvider $provider) { + public function changeLock($path, $type, ILockingProvider $provider): void { /** @var ILockingStorage $targetStorage */ [$targetStorage, $targetInternalPath] = $this->resolvePath($path); $targetStorage->changeLock($targetInternalPath, $type, $provider); } - /** - * @return array [ available, last_checked ] - */ - public function getAvailability() { + public function getAvailability(): array { // shares do not participate in availability logic return [ 'available' => true, @@ -527,10 +503,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha ]; } - /** - * @param bool $isAvailable - */ - public function setAvailability($isAvailable) { + public function setAvailability($isAvailable): void { // shares do not participate in availability logic } @@ -539,7 +512,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->nonMaskedStorage; } - public function getWrapperStorage() { + public function getWrapperStorage(): Storage { $this->init(); /** @@ -554,7 +527,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return $this->storage; } - public function file_get_contents($path) { + public function file_get_contents($path): string|false { $info = [ 'target' => $this->getMountPoint() . '/' . $path, 'source' => $this->getUnjailedPath($path), @@ -563,7 +536,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha return parent::file_get_contents($path); } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): int|float|false { $info = [ 'target' => $this->getMountPoint() . '/' . $path, 'source' => $this->getUnjailedPath($path), @@ -580,7 +553,7 @@ class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements LegacyISha $this->mountOptions = $options; } - public function getUnjailedPath($path) { + public function getUnjailedPath($path): string { $this->init(); return parent::getUnjailedPath($path); } diff --git a/apps/files_sharing/tests/ExternalStorageTest.php b/apps/files_sharing/tests/ExternalStorageTest.php index 56a1f320030..90aad4dca6e 100644 --- a/apps/files_sharing/tests/ExternalStorageTest.php +++ b/apps/files_sharing/tests/ExternalStorageTest.php @@ -95,7 +95,8 @@ class ExternalStorageTest extends \Test\TestCase { } public function testIfTestReturnsTheValue(): void { - $result = $this->getTestStorage('https://remoteserver')->test(); + $storage = $this->getTestStorage('https://remoteserver'); + $result = $storage->test(); $this->assertSame(true, $result); } } @@ -108,9 +109,9 @@ class TestSharingExternalStorage extends \OCA\Files_Sharing\External\Storage { return $this->createBaseUri(); } - public function stat($path) { + public function stat($path): array|false { if ($path === '') { - return true; + return ['key' => 'value']; } return parent::stat($path); } diff --git a/apps/files_trashbin/lib/Storage.php b/apps/files_trashbin/lib/Storage.php index c05d248c9d0..23a0e5bd919 100644 --- a/apps/files_trashbin/lib/Storage.php +++ b/apps/files_trashbin/lib/Storage.php @@ -48,14 +48,7 @@ class Storage extends Wrapper { parent::__construct($parameters); } - /** - * Deletes the given file by moving it into the trashbin. - * - * @param string $path path of file or folder to delete - * - * @return bool true if the operation succeeded, false otherwise - */ - public function unlink($path) { + public function unlink($path): bool { if ($this->trashEnabled) { try { return $this->doDelete($path, 'unlink'); @@ -72,14 +65,7 @@ class Storage extends Wrapper { } } - /** - * Deletes the given folder by moving it into the trashbin. - * - * @param string $path path of folder to delete - * - * @return bool true if the operation succeeded, false otherwise - */ - public function rmdir($path) { + public function rmdir($path): bool { if ($this->trashEnabled) { return $this->doDelete($path, 'rmdir'); } else { @@ -94,7 +80,7 @@ class Storage extends Wrapper { * @param $path * @return bool */ - protected function shouldMoveToTrash($path) { + protected function shouldMoveToTrash($path): bool { $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); $parts = explode('/', $normalized); if (count($parts) < 4 || strpos($normalized, '/appdata_') === 0) { @@ -132,7 +118,7 @@ class Storage extends Wrapper { * @param Node $node * @return MoveToTrashEvent */ - protected function createMoveToTrashEvent(Node $node) { + protected function createMoveToTrashEvent(Node $node): MoveToTrashEvent { return new MoveToTrashEvent($node); } @@ -144,7 +130,7 @@ class Storage extends Wrapper { * * @return bool true if the operation succeeded, false otherwise */ - private function doDelete($path, $method) { + private function doDelete($path, $method): bool { if ( !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin') || (pathinfo($path, PATHINFO_EXTENSION) === 'part') @@ -170,7 +156,7 @@ class Storage extends Wrapper { /** * Setup the storage wrapper callback */ - public static function setupStorage() { + public static function setupStorage(): void { $trashManager = \OC::$server->get(ITrashManager::class); $userManager = \OC::$server->get(IUserManager::class); $logger = \OC::$server->get(LoggerInterface::class); @@ -195,7 +181,7 @@ class Storage extends Wrapper { return $this->mountPoint; } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { $sourceIsTrashbin = $sourceStorage->instanceOfStorage(Storage::class); try { // the fallback for moving between storage involves a copy+delete @@ -219,11 +205,11 @@ class Storage extends Wrapper { } } - protected function disableTrash() { + protected function disableTrash(): void { $this->trashEnabled = false; } - protected function enableTrash() { + protected function enableTrash(): void { $this->trashEnabled = true; } } diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index f0f3159b32a..9de4bf0cc13 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -29,11 +29,11 @@ use Psr\Log\LoggerInterface; use Test\Traits\MountProviderTrait; class TemporaryNoCross extends Temporary { - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null): bool { return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } } diff --git a/apps/workflowengine/tests/Check/FileMimeTypeTest.php b/apps/workflowengine/tests/Check/FileMimeTypeTest.php index 1fc5118c5c4..0911a47f894 100644 --- a/apps/workflowengine/tests/Check/FileMimeTypeTest.php +++ b/apps/workflowengine/tests/Check/FileMimeTypeTest.php @@ -16,7 +16,7 @@ use OCP\IRequest; use Test\TestCase; class TemporaryNoLocal extends Temporary { - public function instanceOfStorage($className) { + public function instanceOfStorage($className): bool { if ($className === '\OC\Files\Storage\Local') { return false; } else { |