From f28e74b7a8b3df11ba1f2e4a18492b8158528cdf Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 1 Oct 2024 16:12:30 +0200 Subject: [PATCH] refactor(Storage): Make all parameter types strong types Signed-off-by: provokateurin --- .../ObjectStore/HomeObjectStoreStorage.php | 2 +- .../Files/ObjectStore/ObjectStoreStorage.php | 58 ++++---- lib/private/Files/Storage/Common.php | 110 ++++++--------- lib/private/Files/Storage/CommonTest.php | 24 ++-- lib/private/Files/Storage/DAV.php | 78 ++++------ lib/private/Files/Storage/FailedStorage.php | 76 +++++----- lib/private/Files/Storage/Home.php | 7 +- lib/private/Files/Storage/Local.php | 73 ++++------ .../Files/Storage/LocalRootStorage.php | 3 +- .../Files/Storage/LocalTempFileTrait.php | 5 +- .../Files/Storage/PolyFill/CopyDirectory.php | 23 +-- lib/private/Files/Storage/Storage.php | 37 +---- lib/private/Files/Storage/StorageFactory.php | 16 +-- .../Files/Storage/Wrapper/Availability.php | 70 ++++----- .../Files/Storage/Wrapper/Encoding.php | 81 +++++------ .../Files/Storage/Wrapper/Encryption.php | 115 +++++---------- lib/private/Files/Storage/Wrapper/Jail.php | 88 ++++++------ .../Files/Storage/Wrapper/KnownMtime.php | 26 ++-- .../Files/Storage/Wrapper/PermissionsMask.php | 37 ++--- lib/private/Files/Storage/Wrapper/Quota.php | 24 ++-- lib/private/Files/Storage/Wrapper/Wrapper.php | 96 +++++++------ .../Lockdown/Filesystem/NullStorage.php | 68 ++++----- .../Files/Storage/IChunkedFileWrite.php | 9 -- lib/public/Files/Storage/ILockingStorage.php | 9 +- lib/public/Files/Storage/INotifyStorage.php | 3 +- lib/public/Files/Storage/ISharedStorage.php | 1 - lib/public/Files/Storage/IStorage.php | 133 ++++++------------ lib/public/Files/Storage/IStorageFactory.php | 9 +- .../Files/Storage/IWriteStreamStorage.php | 3 +- tests/lib/Files/Mount/MountPointTest.php | 8 +- tests/lib/Files/Storage/CopyDirectoryTest.php | 6 +- tests/lib/Files/ViewTest.php | 12 +- 32 files changed, 542 insertions(+), 768 deletions(-) diff --git a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php index feca1f6b4f5..eb95c0b4bf7 100644 --- a/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/HomeObjectStoreStorage.php @@ -32,7 +32,7 @@ class HomeObjectStoreStorage extends ObjectStoreStorage implements IHomeStorage return 'object::user:' . $this->user->getUID(); } - public function getOwner($path): string|false { + public function getOwner(string $path): string|false { return $this->user->getUID(); } diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index 5f568a3aba3..b07b6955b1a 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -66,7 +66,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil $this->logger = \OCP\Server::get(LoggerInterface::class); } - public function mkdir($path, bool $force = false): bool { + public function mkdir(string $path, bool $force = false): bool { $path = $this->normalizePath($path); if (!$force && $this->file_exists($path)) { $this->logger->warning("Tried to create an object store folder that already exists: $path"); @@ -111,11 +111,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } } - /** - * @param string $path - * @return string - */ - private function normalizePath($path) { + private function normalizePath(string $path): string { $path = trim($path, '/'); //FIXME why do we sometimes get a path like 'files//username'? $path = str_replace('//', '/', $path); @@ -132,7 +128,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil * Object Stores use a NoopScanner because metadata is directly stored in * the file cache and cannot really scan the filesystem. The storage passed in is not used anywhere. */ - public function getScanner($path = '', $storage = null): IScanner { + public function getScanner(string $path = '', ?IStorage $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -147,7 +143,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return $this->id; } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $path = $this->normalizePath($path); $entry = $this->getCache()->get($path); @@ -179,7 +175,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return true; } - public function unlink($path): bool { + public function unlink(string $path): bool { $path = $this->normalizePath($path); $entry = $this->getCache()->get($path); @@ -215,7 +211,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return true; } - public function stat($path): array|false { + public function stat(string $path): array|false { $path = $this->normalizePath($path); $cacheEntry = $this->getCache()->get($path); if ($cacheEntry instanceof CacheEntry) { @@ -232,7 +228,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } } - public function getPermissions($path): int { + public function getPermissions(string $path): int { $stat = $this->stat($path); if (is_array($stat) && isset($stat['permissions'])) { @@ -247,17 +243,13 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil * The default implementations just appends the fileId to 'urn:oid:'. Make sure the URN is unique over all users. * You may need a mapping table to store your URN if it cannot be generated from the fileid. * - * @param int $fileId the fileid - * @return null|string the unified resource name used to identify the object + * @return string the unified resource name used to identify the object */ - public function getURN($fileId) { - if (is_numeric($fileId)) { - return $this->objectPrefix . $fileId; - } - return null; + public function getURN(int $fileId): string { + return $this->objectPrefix . $fileId; } - public function opendir($path) { + public function opendir(string $path) { $path = $this->normalizePath($path); try { @@ -274,7 +266,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } } - public function filetype($path): string|false { + public function filetype(string $path): string|false { $path = $this->normalizePath($path); $stat = $this->stat($path); if ($stat) { @@ -287,7 +279,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $path = $this->normalizePath($path); if (strrpos($path, '.') !== false) { @@ -379,12 +371,12 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return false; } - public function file_exists($path): bool { + public function file_exists(string $path): bool { $path = $this->normalizePath($path); return (bool)$this->stat($path); } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); $this->remove($target); @@ -393,12 +385,12 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return true; } - public function getMimeType($path): string|false { + public function getMimeType(string $path): string|false { $path = $this->normalizePath($path); return parent::getMimeType($path); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { if (is_null($mtime)) { $mtime = time(); } @@ -444,12 +436,12 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return true; } - public function writeBack($tmpFile, $path) { + public function writeBack(string $tmpFile, string $path) { $size = filesize($tmpFile); $this->writeStream($path, fopen($tmpFile, 'r'), $size); } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { return false; } @@ -457,7 +449,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return false; } - public function file_put_contents($path, $data): int { + public function file_put_contents(string $path, mixed $data): int { $fh = fopen('php://temp', 'w+'); fwrite($fh, $data); rewind($fh); @@ -567,9 +559,9 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil public function copyFromStorage( IStorage $sourceStorage, - $sourceInternalPath, - $targetInternalPath, - $preserveMtime = false, + string $sourceInternalPath, + string $targetInternalPath, + bool $preserveMtime = false, ): bool { if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class)) { /** @var ObjectStoreStorage $sourceStorage */ @@ -591,7 +583,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool { $sourceCache = $sourceStorage->getCache(); if ($sourceStorage->instanceOfStorage(ObjectStoreStorage::class) && $sourceStorage->getObjectStore()->getStorageId() === $this->getObjectStore()->getStorageId()) { $this->getCache()->moveFromCache($sourceCache, $sourceInternalPath, $targetInternalPath); @@ -663,7 +655,7 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil } } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { $source = $this->normalizePath($source); $target = $this->normalizePath($target); diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 3a2b819fc44..6006c477440 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -68,12 +68,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, public function __construct($parameters) { } - /** - * Remove a file or folder - * - * @param string $path - */ - protected function remove($path): bool { + protected function remove(string $path): bool { if ($this->is_dir($path)) { return $this->rmdir($path); } elseif ($this->is_file($path)) { @@ -83,15 +78,15 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - public function is_dir($path): bool { + public function is_dir(string $path): bool { return $this->filetype($path) === 'dir'; } - public function is_file($path): bool { + public function is_file(string $path): bool { return $this->filetype($path) === 'file'; } - public function filesize($path): int|float|false { + public function filesize(string $path): int|float|false { if ($this->is_dir($path)) { return 0; //by definition } else { @@ -104,27 +99,27 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - public function isReadable($path): bool { + public function isReadable(string $path): bool { // at least check whether it exists // subclasses might want to implement this more thoroughly return $this->file_exists($path); } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { // at least check whether it exists // subclasses might want to implement this more thoroughly // a non-existing file/folder isn't updatable return $this->file_exists($path); } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { if ($this->is_dir($path) && $this->isUpdatable($path)) { return true; } return false; } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { if ($path === '' || $path === '/') { return $this->isUpdatable($path); } @@ -132,11 +127,11 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $this->isUpdatable($parent) && $this->isUpdatable($path); } - public function isSharable($path): bool { + public function isSharable(string $path): bool { return $this->isReadable($path); } - public function getPermissions($path): int { + public function getPermissions(string $path): int { $permissions = 0; if ($this->isCreatable($path)) { $permissions |= \OCP\Constants::PERMISSION_CREATE; @@ -156,7 +151,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $permissions; } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { $stat = $this->stat($path); if (isset($stat['mtime']) && $stat['mtime'] > 0) { return $stat['mtime']; @@ -165,7 +160,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - public function file_get_contents($path): string|false { + public function file_get_contents(string $path): string|false { $handle = $this->fopen($path, 'r'); if (!$handle) { return false; @@ -175,7 +170,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $data; } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { $handle = $this->fopen($path, 'w'); if (!$handle) { return false; @@ -186,14 +181,14 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $count; } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $this->remove($target); $this->removeCachedFile($source); return $this->copy($source, $target) and $this->remove($source); } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { if ($this->is_dir($source)) { $this->remove($target); $dir = $this->opendir($source); @@ -220,7 +215,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - public function getMimeType($path): string|false { + public function getMimeType(string $path): string|false { if ($this->is_dir($path)) { return 'httpd/unix-directory'; } elseif ($this->file_exists($path)) { @@ -230,7 +225,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - public function hash($type, $path, $raw = false): string|false { + public function hash(string $type, string $path, bool $raw = false): string|false { $fh = $this->fopen($path, 'rb'); $ctx = hash_init($type); hash_update_stream($ctx, $fh); @@ -238,11 +233,11 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return hash_final($ctx, $raw); } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { return $this->getCachedFile($path); } - private function addLocalFolder($path, $target): void { + private function addLocalFolder(string $path, string $target): void { $dh = $this->opendir($path); if (is_resource($dh)) { while (($file = readdir($dh)) !== false) { @@ -259,7 +254,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - protected function searchInDir($query, $dir = ''): array { + protected function searchInDir(string $query, string $dir = ''): array { $files = []; $dh = $this->opendir($dir); if (is_resource($dh)) { @@ -288,7 +283,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, * exclusive access to the backend and will not pick up files that have been added in a way that circumvents * Nextcloud filesystem. */ - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { return $this->filemtime($path) > $time; } @@ -300,7 +295,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $dependencies; } - public function getCache($path = '', $storage = null): ICache { + public function getCache(string $path = '', ?IStorage $storage = null): ICache { if (!$storage) { $storage = $this; } @@ -311,7 +306,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $storage->cache; } - public function getScanner($path = '', $storage = null): IScanner { + public function getScanner(string $path = '', ?IStorage $storage = null): IScanner { if (!$storage) { $storage = $this; } @@ -324,7 +319,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $storage->scanner; } - public function getWatcher($path = '', $storage = null): IWatcher { + public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher { if (!$storage) { $storage = $this; } @@ -336,7 +331,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $this->watcher; } - public function getPropagator($storage = null): IPropagator { + public function getPropagator(?IStorage $storage = null): IPropagator { if (!$storage) { $storage = $this; } @@ -351,7 +346,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $storage->propagator; } - public function getUpdater($storage = null): IUpdater { + public function getUpdater(?IStorage $storage = null): IUpdater { if (!$storage) { $storage = $this; } @@ -365,13 +360,13 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $storage->updater; } - public function getStorageCache($storage = null): \OC\Files\Cache\Storage { + public function getStorageCache(?IStorage $storage = null): \OC\Files\Cache\Storage { /** @var Cache $cache */ - $cache = $this->getCache($storage); + $cache = $this->getCache(storage: $storage); return $cache->getStorageCache(); } - public function getOwner($path): string|false { + public function getOwner(string $path): string|false { if ($this->owner === null) { $this->owner = \OC_User::getUser(); } @@ -379,7 +374,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $this->owner; } - public function getETag($path): string|false { + public function getETag(string $path): string|false { return uniqid(); } @@ -390,7 +385,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, * @param string $path The path to clean * @return string cleaned path */ - public function cleanPath($path): string { + public function cleanPath(string $path): string { if (strlen($path) == 0 or $path[0] != '/') { $path = '/' . $path; } @@ -426,7 +421,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { return \OCP\Files\FileInfo::SPACE_UNKNOWN; } @@ -438,10 +433,8 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, /** * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class - * - * @param string $class */ - public function instanceOfStorage($class): bool { + public function instanceOfStorage(string $class): bool { if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') { // FIXME Temporary fix to keep existing checks working $class = '\OCA\Files_Sharing\SharedStorage'; @@ -453,14 +446,12 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, * A custom storage implementation can return an url for direct download of a give file. * * For now the returned array can hold the parameter url - in future more attributes might follow. - * - * @param string $path */ - public function getDirectDownload($path): array|false { + public function getDirectDownload(string $path): array|false { return []; } - public function verifyPath($path, $fileName): void { + public function verifyPath(string $path, string $fileName): void { $this->getFilenameValidator() ->validateFilename($fileName); @@ -493,20 +484,11 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, $this->mountOptions = $options; } - /** - * @param string $name - * @param mixed $default - */ - public function getMountOption($name, $default = null): mixed { + public function getMountOption(string $name, mixed $default = null): mixed { return $this->mountOptions[$name] ?? $default; } - /** - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @param bool $preserveMtime - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } @@ -563,11 +545,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $storage === $this; } - /** - * @param string $sourceInternalPath - * @param string $targetInternalPath - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($this->isSameStorage($sourceStorage)) { // resolve any jailed paths while ($sourceStorage->instanceOfStorage(Jail::class)) { @@ -607,7 +585,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $result; } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { if (Filesystem::isFileBlacklisted($path)) { throw new ForbiddenException('Invalid path: ' . $path, false); } @@ -637,7 +615,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $data; } - public function acquireLock($path, $type, ILockingProvider $provider): void { + public function acquireLock(string $path, int $type, ILockingProvider $provider): void { $logger = $this->getLockLogger(); if ($logger) { $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; @@ -664,7 +642,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - public function releaseLock($path, $type, ILockingProvider $provider): void { + public function releaseLock(string $path, int $type, ILockingProvider $provider): void { $logger = $this->getLockLogger(); if ($logger) { $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; @@ -691,7 +669,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, } } - public function changeLock($path, $type, ILockingProvider $provider): void { + public function changeLock(string $path, int $type, ILockingProvider $provider): void { $logger = $this->getLockLogger(); if ($logger) { $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; @@ -733,7 +711,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $this->getStorageCache()->getAvailability(); } - public function setAvailability($isAvailable): void { + public function setAvailability(bool $isAvailable): void { $this->getStorageCache()->setAvailability($isAvailable); } @@ -762,7 +740,7 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, return $count; } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { $dh = $this->opendir($directory); if ($dh === false) { diff --git a/lib/private/Files/Storage/CommonTest.php b/lib/private/Files/Storage/CommonTest.php index 1145fa2501d..bf61dfaec86 100644 --- a/lib/private/Files/Storage/CommonTest.php +++ b/lib/private/Files/Storage/CommonTest.php @@ -21,40 +21,40 @@ class CommonTest extends \OC\Files\Storage\Common { public function getId(): string { return 'test::' . $this->storage->getId(); } - public function mkdir($path): bool { + public function mkdir(string $path): bool { return $this->storage->mkdir($path); } - public function rmdir($path): bool { + public function rmdir(string $path): bool { return $this->storage->rmdir($path); } - public function opendir($path) { + public function opendir(string $path) { return $this->storage->opendir($path); } - public function stat($path): array|false { + public function stat(string $path): array|false { return $this->storage->stat($path); } - public function filetype($path): string|false { + public function filetype(string $path): string|false { return @$this->storage->filetype($path); } - public function isReadable($path): bool { + public function isReadable(string $path): bool { return $this->storage->isReadable($path); } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return $this->storage->isUpdatable($path); } - public function file_exists($path): bool { + public function file_exists(string $path): bool { return $this->storage->file_exists($path); } - public function unlink($path): bool { + public function unlink(string $path): bool { return $this->storage->unlink($path); } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { return $this->storage->fopen($path, $mode); } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { return $this->storage->free_space($path); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { return $this->storage->touch($path, $mtime); } } diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 0d57625645b..e310e4357f1 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -194,7 +194,7 @@ class DAV extends Common { return $baseUri; } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $this->init(); $path = $this->cleanPath($path); $result = $this->simpleResponse('MKCOL', $path, null, 201); @@ -204,7 +204,7 @@ class DAV extends Common { return $result; } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $this->init(); $path = $this->cleanPath($path); // FIXME: some WebDAV impl return 403 when trying to DELETE @@ -215,7 +215,7 @@ class DAV extends Common { return $result; } - public function opendir($path) { + public function opendir(string $path) { $this->init(); $path = $this->cleanPath($path); try { @@ -243,7 +243,7 @@ class DAV extends Common { * * @throws ClientHttpException */ - protected function propfind($path): array|false { + protected function propfind(string $path): array|false { $path = $this->cleanPath($path); $cachedResponse = $this->statCache->get($path); // we either don't know it, or we know it exists but need more details @@ -271,7 +271,7 @@ class DAV extends Common { return $response; } - public function filetype($path): string|false { + public function filetype(string $path): string|false { try { $response = $this->propfind($path); if ($response === false) { @@ -289,7 +289,7 @@ class DAV extends Common { return false; } - public function file_exists($path): bool { + public function file_exists(string $path): bool { try { $path = $this->cleanPath($path); $cachedState = $this->statCache->get($path); @@ -307,7 +307,7 @@ class DAV extends Common { return false; } - public function unlink($path): bool { + public function unlink(string $path): bool { $this->init(); $path = $this->cleanPath($path); $result = $this->simpleResponse('DELETE', $path, null, 204); @@ -316,7 +316,7 @@ class DAV extends Common { return $result; } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $this->init(); $path = $this->cleanPath($path); switch ($mode) { @@ -390,15 +390,12 @@ class DAV extends Common { } } - /** - * @param string $tmpFile - */ - public function writeBack($tmpFile, $path): void { + public function writeBack(string $tmpFile, string $path): void { $this->uploadFile($tmpFile, $path); unlink($tmpFile); } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { $this->init(); $path = $this->cleanPath($path); try { @@ -416,7 +413,7 @@ class DAV extends Common { } } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { $this->init(); if (is_null($mtime)) { $mtime = time(); @@ -453,23 +450,14 @@ class DAV extends Common { return true; } - /** - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { $path = $this->cleanPath($path); $result = parent::file_put_contents($path, $data); $this->statCache->remove($path); return $result; } - /** - * @param string $path - * @param string $target - */ - protected function uploadFile($path, $target): void { + protected function uploadFile(string $path, string $target): void { $this->init(); // invalidate @@ -489,7 +477,7 @@ class DAV extends Common { $this->removeCachedFile($target); } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $this->init(); $source = $this->cleanPath($source); $target = $this->cleanPath($target); @@ -520,7 +508,7 @@ class DAV extends Common { return false; } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { $this->init(); $source = $this->cleanPath($source); $target = $this->cleanPath($target); @@ -548,7 +536,7 @@ class DAV extends Common { return false; } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { if (Filesystem::isFileBlacklisted($path)) { throw new ForbiddenException('Invalid path: ' . $path, false); } @@ -610,18 +598,18 @@ class DAV extends Common { ]; } - public function stat($path): array|false { + public function stat(string $path): array|false { $meta = $this->getMetaData($path); return $meta ?: false; } - public function getMimeType($path): string|false { + public function getMimeType(string $path): string|false { $meta = $this->getMetaData($path); return $meta ? $meta['mimetype'] : false; } - public function cleanPath($path): string { + public function cleanPath(string $path): string { if ($path === '') { return $path; } @@ -636,21 +624,17 @@ class DAV extends Common { * @param string $path to encode * @return string encoded path */ - protected function encodePath($path): string { + protected function encodePath(string $path): string { // slashes need to stay return str_replace('%2F', '/', rawurlencode($path)); } /** - * @param string $method - * @param string $path - * @param string|resource|null $body - * @param int $expected * @return bool * @throws StorageInvalidException * @throws StorageNotAvailableException */ - protected function simpleResponse($method, $path, $body, $expected): bool { + protected function simpleResponse(string $method, string $path, ?string $body, int $expected): bool { $path = $this->cleanPath($path); try { $response = $this->client->request($method, $this->encodePath($path), $body); @@ -676,33 +660,33 @@ class DAV extends Common { return true; } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return (bool)($this->getPermissions($path) & Constants::PERMISSION_UPDATE); } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { return (bool)($this->getPermissions($path) & Constants::PERMISSION_CREATE); } - public function isSharable($path): bool { + public function isSharable(string $path): bool { return (bool)($this->getPermissions($path) & Constants::PERMISSION_SHARE); } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { return (bool)($this->getPermissions($path) & Constants::PERMISSION_DELETE); } - public function getPermissions($path): int { + public function getPermissions(string $path): int { $stat = $this->getMetaData($path); return $stat ? $stat['permissions'] : 0; } - public function getETag($path): string|false { + public function getETag(string $path): string|false { $meta = $this->getMetaData($path); return $meta ? $meta['etag'] : false; } - protected function parsePermissions($permissionsString): int { + protected function parsePermissions(string $permissionsString): int { $permissions = Constants::PERMISSION_READ; if (str_contains($permissionsString, 'R')) { $permissions |= Constants::PERMISSION_SHARE; @@ -720,7 +704,7 @@ class DAV extends Common { return $permissions; } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { $this->init(); $path = $this->cleanPath($path); try { @@ -786,7 +770,7 @@ class DAV extends Common { * which might be temporary * @throws ForbiddenException if the action is not allowed */ - protected function convertException(Exception $e, $path = ''): void { + protected function convertException(Exception $e, string $path = ''): void { Server::get(LoggerInterface::class)->debug($e->getMessage(), ['app' => 'files_external', 'exception' => $e]); if ($e instanceof ClientHttpException) { if ($e->getHttpStatus() === Http::STATUS_LOCKED) { @@ -818,7 +802,7 @@ class DAV extends Common { // TODO: only log for now, but in the future need to wrap/rethrow exception } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { $this->init(); $directory = $this->cleanPath($directory); try { diff --git a/lib/private/Files/Storage/FailedStorage.php b/lib/private/Files/Storage/FailedStorage.php index 35c78bd3269..1c91a775525 100644 --- a/lib/private/Files/Storage/FailedStorage.php +++ b/lib/private/Files/Storage/FailedStorage.php @@ -34,146 +34,146 @@ class FailedStorage extends Common { return 'failedstorage'; } - public function mkdir($path): never { + public function mkdir(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function rmdir($path): never { + public function rmdir(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function opendir($path): never { + public function opendir(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function is_dir($path): never { + public function is_dir(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function is_file($path): never { + public function is_file(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function stat($path): never { + public function stat(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function filetype($path): never { + public function filetype(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function filesize($path): never { + public function filesize(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isCreatable($path): never { + public function isCreatable(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isReadable($path): never { + public function isReadable(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isUpdatable($path): never { + public function isUpdatable(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isDeletable($path): never { + public function isDeletable(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function isSharable($path): never { + public function isSharable(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getPermissions($path): never { + public function getPermissions(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function file_exists($path): never { + public function file_exists(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function filemtime($path): never { + public function filemtime(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function file_get_contents($path): never { + public function file_get_contents(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function file_put_contents($path, $data): never { + public function file_put_contents(string $path, mixed $data): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function unlink($path): never { + public function unlink(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function rename($source, $target): never { + public function rename(string $source, string $target): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function copy($source, $target): never { + public function copy(string $source, string $target): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function fopen($path, $mode): never { + public function fopen(string $path, string $mode): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getMimeType($path): never { + public function getMimeType(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function hash($type, $path, $raw = false): never { + public function hash(string $type, string $path, bool $raw = false): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function free_space($path): never { + public function free_space(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function touch($path, $mtime = null): never { + public function touch(string $path, ?int $mtime = null): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getLocalFile($path): never { + public function getLocalFile(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function hasUpdated($path, $time): never { + public function hasUpdated(string $path, int $time): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getETag($path): never { + public function getETag(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getDirectDownload($path): never { + public function getDirectDownload(string $path): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function verifyPath($path, $fileName): void { + public function verifyPath(string $path, string $fileName): void { } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): never { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): never { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function acquireLock($path, $type, ILockingProvider $provider): never { + public function acquireLock(string $path, int $type, ILockingProvider $provider): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function releaseLock($path, $type, ILockingProvider $provider): never { + public function releaseLock(string $path, int $type, ILockingProvider $provider): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function changeLock($path, $type, ILockingProvider $provider): never { + public function changeLock(string $path, int $type, ILockingProvider $provider): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } @@ -181,11 +181,11 @@ class FailedStorage extends Common { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function setAvailability($isAvailable): never { + public function setAvailability(bool $isAvailable): never { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function getCache($path = '', $storage = null): FailedCache { + public function getCache(string $path = '', ?IStorage $storage = null): FailedCache { return new FailedCache(); } } diff --git a/lib/private/Files/Storage/Home.php b/lib/private/Files/Storage/Home.php index 6729b293860..5280cb26ff3 100644 --- a/lib/private/Files/Storage/Home.php +++ b/lib/private/Files/Storage/Home.php @@ -10,6 +10,7 @@ namespace OC\Files\Storage; use OC\Files\Cache\HomePropagator; use OCP\Files\Cache\ICache; use OCP\Files\Cache\IPropagator; +use OCP\Files\Storage\IStorage; use OCP\IUser; /** @@ -44,7 +45,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage { return $this->id; } - public function getCache($path = '', $storage = null): ICache { + public function getCache(string $path = '', ?IStorage $storage = null): ICache { if (!$storage) { $storage = $this; } @@ -54,7 +55,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage { return $this->cache; } - public function getPropagator($storage = null): IPropagator { + public function getPropagator(?IStorage $storage = null): IPropagator { if (!$storage) { $storage = $this; } @@ -69,7 +70,7 @@ class Home extends Local implements \OCP\Files\IHomeStorage { return $this->user; } - public function getOwner($path): string|false { + public function getOwner(string $path): string|false { return $this->user->getUID(); } } diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 8d1c2d4c508..9e3ec663f03 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -78,7 +78,7 @@ class Local extends \OC\Files\Storage\Common { return 'local::' . $this->datadir; } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $sourcePath = $this->getSourcePath($path); $oldMask = umask($this->defUMask); $result = @mkdir($sourcePath, 0777, true); @@ -86,7 +86,7 @@ class Local extends \OC\Files\Storage\Common { return $result; } - public function rmdir($path): bool { + public function rmdir(string $path): bool { if (!$this->isDeletable($path)) { return false; } @@ -125,11 +125,11 @@ class Local extends \OC\Files\Storage\Common { } } - public function opendir($path) { + public function opendir(string $path) { return opendir($this->getSourcePath($path)); } - public function is_dir($path): bool { + public function is_dir(string $path): bool { if ($this->caseInsensitive && !$this->file_exists($path)) { return false; } @@ -139,14 +139,14 @@ class Local extends \OC\Files\Storage\Common { return is_dir($this->getSourcePath($path)); } - public function is_file($path): bool { + public function is_file(string $path): bool { if ($this->caseInsensitive && !$this->file_exists($path)) { return false; } return is_file($this->getSourcePath($path)); } - public function stat($path): array|false { + public function stat(string $path): array|false { $fullPath = $this->getSourcePath($path); clearstatcache(true, $fullPath); if (!file_exists($fullPath)) { @@ -164,7 +164,7 @@ class Local extends \OC\Files\Storage\Common { return $statResult; } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { try { $stat = $this->stat($path); } catch (ForbiddenException $e) { @@ -213,7 +213,7 @@ class Local extends \OC\Files\Storage\Common { return $data; } - public function filetype($path): string|false { + public function filetype(string $path): string|false { $filetype = filetype($this->getSourcePath($path)); if ($filetype == 'link') { $filetype = filetype(realpath($this->getSourcePath($path))); @@ -221,7 +221,7 @@ class Local extends \OC\Files\Storage\Common { return $filetype; } - public function filesize($path): int|float|false { + public function filesize(string $path): int|float|false { if (!$this->is_file($path)) { return 0; } @@ -233,15 +233,15 @@ class Local extends \OC\Files\Storage\Common { return filesize($fullPath); } - public function isReadable($path): bool { + public function isReadable(string $path): bool { return is_readable($this->getSourcePath($path)); } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return is_writable($this->getSourcePath($path)); } - public function file_exists($path): bool { + public function file_exists(string $path): bool { if ($this->caseInsensitive) { $fullPath = $this->getSourcePath($path); $parentPath = dirname($fullPath); @@ -255,7 +255,7 @@ class Local extends \OC\Files\Storage\Common { } } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { $fullPath = $this->getSourcePath($path); clearstatcache(true, $fullPath); if (!$this->file_exists($path)) { @@ -268,7 +268,7 @@ class Local extends \OC\Files\Storage\Common { return filemtime($fullPath); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { // sets the modification time of the file to the given value. // If mtime is nil the current time is set. // note that the access time of the file always changes to the current time. @@ -289,11 +289,11 @@ class Local extends \OC\Files\Storage\Common { return $result; } - public function file_get_contents($path): string|false { + public function file_get_contents(string $path): string|false { return file_get_contents($this->getSourcePath($path)); } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { $oldMask = umask($this->defUMask); if ($this->unlinkOnTruncate) { $this->unlink($path); @@ -303,7 +303,7 @@ class Local extends \OC\Files\Storage\Common { return $result; } - public function unlink($path): bool { + public function unlink(string $path): bool { if ($this->is_dir($path)) { return $this->rmdir($path); } elseif ($this->is_file($path)) { @@ -323,7 +323,7 @@ class Local extends \OC\Files\Storage\Common { } } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $srcParent = dirname($source); $dstParent = dirname($target); @@ -364,7 +364,7 @@ class Local extends \OC\Files\Storage\Common { return $this->copy($source, $target) && $this->unlink($source); } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { if ($this->is_dir($source)) { return parent::copy($source, $target); } else { @@ -383,7 +383,7 @@ class Local extends \OC\Files\Storage\Common { } } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $sourcePath = $this->getSourcePath($path); if (!file_exists($sourcePath) && $mode === 'r') { return false; @@ -397,11 +397,11 @@ class Local extends \OC\Files\Storage\Common { return $result; } - public function hash($type, $path, $raw = false): string|false { + public function hash(string $type, string $path, bool $raw = false): string|false { return hash_file($type, $this->getSourcePath($path), $raw); } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { $sourcePath = $this->getSourcePath($path); // using !is_dir because $sourcePath might be a part file or // non-existing file, so we'd still want to use the parent dir @@ -417,19 +417,15 @@ class Local extends \OC\Files\Storage\Common { return Util::numericToNumber($space); } - public function search($query): array { + public function search(string $query): array { return $this->searchInDir($query); } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { return $this->getSourcePath($path); } - /** - * @param string $query - * @param string $dir - */ - protected function searchInDir($query, $dir = ''): array { + protected function searchInDir(string $query, string $dir = ''): array { $files = []; $physicalDir = $this->getSourcePath($dir); foreach (scandir($physicalDir) as $item) { @@ -448,7 +444,7 @@ class Local extends \OC\Files\Storage\Common { return $files; } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { if ($this->file_exists($path)) { return $this->filemtime($path) > $time; } else { @@ -459,10 +455,9 @@ class Local extends \OC\Files\Storage\Common { /** * Get the source path (on disk) of a given path * - * @param string $path * @throws ForbiddenException */ - public function getSourcePath($path): string { + public function getSourcePath(string $path): string { if (Filesystem::isFileBlacklisted($path)) { throw new ForbiddenException('Invalid path: ' . $path, false); } @@ -498,7 +493,7 @@ class Local extends \OC\Files\Storage\Common { return true; } - public function getETag($path): string|false { + public function getETag(string $path): string|false { return $this->calculateEtag($path, $this->stat($path)); } @@ -529,7 +524,7 @@ class Local extends \OC\Files\Storage\Common { } private function canDoCrossStorageMove(IStorage $sourceStorage): bool { - /** @psalm-suppress UndefinedClass */ + /** @psalm-suppress UndefinedClass,InvalidArgument */ return $sourceStorage->instanceOfStorage(Local::class) // Don't treat ACLStorageWrapper like local storage where copy can be done directly. // Instead, use the slower recursive copying in php from Common::copyFromStorage with @@ -541,7 +536,7 @@ class Local extends \OC\Files\Storage\Common { && !$sourceStorage->instanceOfStorage(Encryption::class); } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): bool { if ($this->canDoCrossStorageMove($sourceStorage)) { if ($sourceStorage->instanceOfStorage(Jail::class)) { /** @@ -559,13 +554,7 @@ class Local extends \OC\Files\Storage\Common { } } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($this->canDoCrossStorageMove($sourceStorage)) { if ($sourceStorage->instanceOfStorage(Jail::class)) { /** diff --git a/lib/private/Files/Storage/LocalRootStorage.php b/lib/private/Files/Storage/LocalRootStorage.php index 6029f05788a..2e0645e092a 100644 --- a/lib/private/Files/Storage/LocalRootStorage.php +++ b/lib/private/Files/Storage/LocalRootStorage.php @@ -10,9 +10,10 @@ namespace OC\Files\Storage; use OC\Files\Cache\LocalRootScanner; use OCP\Files\Cache\IScanner; +use OCP\Files\Storage\IStorage; class LocalRootStorage extends Local { - public function getScanner($path = '', $storage = null): IScanner { + public function getScanner(string $path = '', ?IStorage $storage = null): IScanner { if (!$storage) { $storage = $this; } diff --git a/lib/private/Files/Storage/LocalTempFileTrait.php b/lib/private/Files/Storage/LocalTempFileTrait.php index 057970dea8f..c8e3588f2e8 100644 --- a/lib/private/Files/Storage/LocalTempFileTrait.php +++ b/lib/private/Files/Storage/LocalTempFileTrait.php @@ -29,10 +29,7 @@ trait LocalTempFileTrait { return $this->cachedFiles[$path]; } - /** - * @param string $path - */ - protected function removeCachedFile($path): void { + protected function removeCachedFile(string $path): void { unset($this->cachedFiles[$path]); } diff --git a/lib/private/Files/Storage/PolyFill/CopyDirectory.php b/lib/private/Files/Storage/PolyFill/CopyDirectory.php index 19833a57348..2f6167ef85e 100644 --- a/lib/private/Files/Storage/PolyFill/CopyDirectory.php +++ b/lib/private/Files/Storage/PolyFill/CopyDirectory.php @@ -10,41 +10,32 @@ namespace OC\Files\Storage\PolyFill; trait CopyDirectory { /** * Check if a path is a directory - * - * @param string $path */ - abstract public function is_dir($path): bool; + abstract public function is_dir(string $path): bool; /** * Check if a file or folder exists - * - * @param string $path */ - abstract public function file_exists($path): bool; + abstract public function file_exists(string $path): bool; /** * Delete a file or folder - * - * @param string $path */ - abstract public function unlink($path): bool; + abstract public function unlink(string $path): bool; /** * Open a directory handle for a folder * - * @param string $path * @return resource|false */ - abstract public function opendir($path); + abstract public function opendir(string $path); /** * Create a new folder - * - * @param string $path */ - abstract public function mkdir($path): bool; + abstract public function mkdir(string $path): bool; - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { if ($this->is_dir($source)) { if ($this->file_exists($target)) { $this->unlink($target); @@ -59,7 +50,7 @@ trait CopyDirectory { /** * For adapters that don't support copying folders natively */ - protected function copyRecursive($source, $target): bool { + protected function copyRecursive(string $source, string $target): bool { $dh = $this->opendir($source); $result = true; while (($file = readdir($dh)) !== false) { diff --git a/lib/private/Files/Storage/Storage.php b/lib/private/Files/Storage/Storage.php index 3b14b1b84e3..aa17c12b309 100644 --- a/lib/private/Files/Storage/Storage.php +++ b/lib/private/Files/Storage/Storage.php @@ -22,46 +22,23 @@ use OCP\Files\Storage\IStorage; * All paths passed to the storage are relative to the storage and should NOT have a leading slash. */ interface Storage extends IStorage, ILockingStorage { - /** - * @param string $path - * @param ?IStorage $storage - */ - public function getCache($path = '', $storage = null): ICache; + public function getCache(string $path = '', ?IStorage $storage = null): ICache; - /** - * @param string $path - * @param ?IStorage $storage - */ - public function getScanner($path = '', $storage = null): IScanner; + public function getScanner(string $path = '', ?IStorage $storage = null): IScanner; - /** - * @param string $path - * @param ?IStorage $storage - */ - public function getWatcher($path = '', $storage = null): IWatcher; + public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher; - /** - * @param ?IStorage $storage - */ - public function getPropagator($storage = null): IPropagator; + public function getPropagator(?IStorage $storage = null): IPropagator; - /** - * @param ?IStorage $storage - */ - public function getUpdater($storage = null): IUpdater; + public function getUpdater(?IStorage $storage = null): IUpdater; public function getStorageCache(): \OC\Files\Cache\Storage; - /** - * @param string $path - */ - public function getMetaData($path): ?array; + public function getMetaData(string $path): ?array; /** * Get the contents of a directory with metadata * - * @param string $directory - * * The metadata array will contain the following fields * * - name @@ -72,5 +49,5 @@ interface Storage extends IStorage, ILockingStorage { * - storage_mtime * - permissions */ - public function getDirectoryContent($directory): \Traversable; + public function getDirectoryContent(string $directory): \Traversable; } diff --git a/lib/private/Files/Storage/StorageFactory.php b/lib/private/Files/Storage/StorageFactory.php index 252f85e03d6..603df7fe007 100644 --- a/lib/private/Files/Storage/StorageFactory.php +++ b/lib/private/Files/Storage/StorageFactory.php @@ -19,7 +19,7 @@ class StorageFactory implements IStorageFactory { */ private $storageWrappers = []; - public function addStorageWrapper($wrapperName, $callback, $priority = 50, $existingMounts = []): bool { + public function addStorageWrapper(string $wrapperName, callable $callback, int $priority = 50, array $existingMounts = []): bool { if (isset($this->storageWrappers[$wrapperName])) { return false; } @@ -37,31 +37,23 @@ class StorageFactory implements IStorageFactory { * Remove a storage wrapper by name. * Note: internal method only to be used for cleanup * - * @param string $wrapperName name of the wrapper * @internal */ - public function removeStorageWrapper($wrapperName): void { + public function removeStorageWrapper(string $wrapperName): void { unset($this->storageWrappers[$wrapperName]); } /** * Create an instance of a storage and apply the registered storage wrappers - * - * @param string $class - * @param array $arguments - * @return IStorage */ - public function getInstance(IMountPoint $mountPoint, $class, $arguments): IStorage { + public function getInstance(IMountPoint $mountPoint, string $class, array $arguments): IStorage { if (!is_a($class, IConstructableStorage::class, true)) { \OCP\Server::get(LoggerInterface::class)->warning('Building a storage not implementing IConstructableStorage is deprecated since 31.0.0', ['class' => $class]); } return $this->wrap($mountPoint, new $class($arguments)); } - /** - * @param IStorage $storage - */ - public function wrap(IMountPoint $mountPoint, $storage): IStorage { + public function wrap(IMountPoint $mountPoint, IStorage $storage): IStorage { $wrappers = array_values($this->storageWrappers); usort($wrappers, function ($a, $b) { return $b['priority'] - $a['priority']; diff --git a/lib/private/Files/Storage/Wrapper/Availability.php b/lib/private/Files/Storage/Wrapper/Availability.php index 1a2824614c1..ffe8f08e40f 100644 --- a/lib/private/Files/Storage/Wrapper/Availability.php +++ b/lib/private/Files/Storage/Wrapper/Availability.php @@ -70,7 +70,7 @@ class Availability extends Wrapper { } } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $this->checkAvailability(); try { return parent::mkdir($path); @@ -80,7 +80,7 @@ class Availability extends Wrapper { } } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $this->checkAvailability(); try { return parent::rmdir($path); @@ -90,7 +90,7 @@ class Availability extends Wrapper { } } - public function opendir($path) { + public function opendir(string $path) { $this->checkAvailability(); try { return parent::opendir($path); @@ -100,7 +100,7 @@ class Availability extends Wrapper { } } - public function is_dir($path): bool { + public function is_dir(string $path): bool { $this->checkAvailability(); try { return parent::is_dir($path); @@ -110,7 +110,7 @@ class Availability extends Wrapper { } } - public function is_file($path): bool { + public function is_file(string $path): bool { $this->checkAvailability(); try { return parent::is_file($path); @@ -120,7 +120,7 @@ class Availability extends Wrapper { } } - public function stat($path): array|false { + public function stat(string $path): array|false { $this->checkAvailability(); try { return parent::stat($path); @@ -130,7 +130,7 @@ class Availability extends Wrapper { } } - public function filetype($path): string|false { + public function filetype(string $path): string|false { $this->checkAvailability(); try { return parent::filetype($path); @@ -140,7 +140,7 @@ class Availability extends Wrapper { } } - public function filesize($path): int|float|false { + public function filesize(string $path): int|float|false { $this->checkAvailability(); try { return parent::filesize($path); @@ -150,7 +150,7 @@ class Availability extends Wrapper { } } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { $this->checkAvailability(); try { return parent::isCreatable($path); @@ -160,7 +160,7 @@ class Availability extends Wrapper { } } - public function isReadable($path): bool { + public function isReadable(string $path): bool { $this->checkAvailability(); try { return parent::isReadable($path); @@ -170,7 +170,7 @@ class Availability extends Wrapper { } } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { $this->checkAvailability(); try { return parent::isUpdatable($path); @@ -180,7 +180,7 @@ class Availability extends Wrapper { } } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { $this->checkAvailability(); try { return parent::isDeletable($path); @@ -190,7 +190,7 @@ class Availability extends Wrapper { } } - public function isSharable($path): bool { + public function isSharable(string $path): bool { $this->checkAvailability(); try { return parent::isSharable($path); @@ -200,7 +200,7 @@ class Availability extends Wrapper { } } - public function getPermissions($path): int { + public function getPermissions(string $path): int { $this->checkAvailability(); try { return parent::getPermissions($path); @@ -210,7 +210,7 @@ class Availability extends Wrapper { } } - public function file_exists($path): bool { + public function file_exists(string $path): bool { if ($path === '') { return true; } @@ -223,7 +223,7 @@ class Availability extends Wrapper { } } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { $this->checkAvailability(); try { return parent::filemtime($path); @@ -233,7 +233,7 @@ class Availability extends Wrapper { } } - public function file_get_contents($path): string|false { + public function file_get_contents(string $path): string|false { $this->checkAvailability(); try { return parent::file_get_contents($path); @@ -243,7 +243,7 @@ class Availability extends Wrapper { } } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { $this->checkAvailability(); try { return parent::file_put_contents($path, $data); @@ -253,7 +253,7 @@ class Availability extends Wrapper { } } - public function unlink($path): bool { + public function unlink(string $path): bool { $this->checkAvailability(); try { return parent::unlink($path); @@ -263,7 +263,7 @@ class Availability extends Wrapper { } } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $this->checkAvailability(); try { return parent::rename($source, $target); @@ -273,7 +273,7 @@ class Availability extends Wrapper { } } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { $this->checkAvailability(); try { return parent::copy($source, $target); @@ -283,7 +283,7 @@ class Availability extends Wrapper { } } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $this->checkAvailability(); try { return parent::fopen($path, $mode); @@ -293,7 +293,7 @@ class Availability extends Wrapper { } } - public function getMimeType($path): string|false { + public function getMimeType(string $path): string|false { $this->checkAvailability(); try { return parent::getMimeType($path); @@ -303,7 +303,7 @@ class Availability extends Wrapper { } } - public function hash($type, $path, $raw = false): string|false { + public function hash(string $type, string $path, bool $raw = false): string|false { $this->checkAvailability(); try { return parent::hash($type, $path, $raw); @@ -313,7 +313,7 @@ class Availability extends Wrapper { } } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { $this->checkAvailability(); try { return parent::free_space($path); @@ -323,7 +323,7 @@ class Availability extends Wrapper { } } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { $this->checkAvailability(); try { return parent::touch($path, $mtime); @@ -333,7 +333,7 @@ class Availability extends Wrapper { } } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { $this->checkAvailability(); try { return parent::getLocalFile($path); @@ -343,7 +343,7 @@ class Availability extends Wrapper { } } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { if (!$this->isAvailable()) { return false; } @@ -356,7 +356,7 @@ class Availability extends Wrapper { } } - public function getOwner($path): string|false { + public function getOwner(string $path): string|false { try { return parent::getOwner($path); } catch (StorageNotAvailableException $e) { @@ -365,7 +365,7 @@ class Availability extends Wrapper { } } - public function getETag($path): string|false { + public function getETag(string $path): string|false { $this->checkAvailability(); try { return parent::getETag($path); @@ -375,7 +375,7 @@ class Availability extends Wrapper { } } - public function getDirectDownload($path): array|false { + public function getDirectDownload(string $path): array|false { $this->checkAvailability(); try { return parent::getDirectDownload($path); @@ -385,7 +385,7 @@ class Availability extends Wrapper { } } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { $this->checkAvailability(); try { return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); @@ -395,7 +395,7 @@ class Availability extends Wrapper { } } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { $this->checkAvailability(); try { return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); @@ -405,7 +405,7 @@ class Availability extends Wrapper { } } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { $this->checkAvailability(); try { return parent::getMetaData($path); @@ -438,7 +438,7 @@ class Availability extends Wrapper { - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { $this->checkAvailability(); try { return parent::getDirectoryContent($directory); diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index 26e0e3a15dd..02b70e5ae60 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -35,10 +35,8 @@ class Encoding extends Wrapper { /** * Returns whether the given string is only made of ASCII characters - * - * @param string $str string */ - private function isAscii($str): bool { + private function isAscii(string $str): bool { return !preg_match('/[\\x80-\\xff]+/', $str); } @@ -47,11 +45,9 @@ class Encoding extends Wrapper { * each form for each path section and returns the correct form. * If no existing path found, returns the path as it was given. * - * @param string $fullPath path to check - * * @return string original or converted path */ - private function findPathToUse($fullPath): string { + private function findPathToUse(string $fullPath): string { $cachedPath = $this->namesCache[$fullPath]; if ($cachedPath !== null) { return $cachedPath; @@ -75,12 +71,11 @@ class Encoding extends Wrapper { * Checks whether the last path section of the given path exists in NFC or NFD form * and returns the correct form. If no existing path found, returns null. * - * @param string $basePath base path to check * @param string $lastSection last section of the path to check for NFD/NFC variations * * @return string|null original or converted path, or null if none of the forms was found */ - private function findPathToUseLastSection($basePath, $lastSection): ?string { + private function findPathToUseLastSection(string $basePath, string $lastSection): ?string { $fullPath = $basePath . $lastSection; if ($lastSection === '' || $this->isAscii($lastSection) || $this->storage->file_exists($fullPath)) { $this->namesCache[$fullPath] = $fullPath; @@ -104,7 +99,7 @@ class Encoding extends Wrapper { return null; } - public function mkdir($path): bool { + public function mkdir(string $path): bool { // note: no conversion here, method should not be called with non-NFC names! $result = $this->storage->mkdir($path); if ($result) { @@ -113,7 +108,7 @@ class Encoding extends Wrapper { return $result; } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $result = $this->storage->rmdir($this->findPathToUse($path)); if ($result) { unset($this->namesCache[$path]); @@ -121,72 +116,72 @@ class Encoding extends Wrapper { return $result; } - public function opendir($path) { + public function opendir(string $path) { $handle = $this->storage->opendir($this->findPathToUse($path)); return EncodingDirectoryWrapper::wrap($handle); } - public function is_dir($path): bool { + public function is_dir(string $path): bool { return $this->storage->is_dir($this->findPathToUse($path)); } - public function is_file($path): bool { + public function is_file(string $path): bool { return $this->storage->is_file($this->findPathToUse($path)); } - public function stat($path): array|false { + public function stat(string $path): array|false { return $this->storage->stat($this->findPathToUse($path)); } - public function filetype($path): string|false { + public function filetype(string $path): string|false { return $this->storage->filetype($this->findPathToUse($path)); } - public function filesize($path): int|float|false { + public function filesize(string $path): int|float|false { return $this->storage->filesize($this->findPathToUse($path)); } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { return $this->storage->isCreatable($this->findPathToUse($path)); } - public function isReadable($path): bool { + public function isReadable(string $path): bool { return $this->storage->isReadable($this->findPathToUse($path)); } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return $this->storage->isUpdatable($this->findPathToUse($path)); } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { return $this->storage->isDeletable($this->findPathToUse($path)); } - public function isSharable($path): bool { + public function isSharable(string $path): bool { return $this->storage->isSharable($this->findPathToUse($path)); } - public function getPermissions($path): int { + public function getPermissions(string $path): int { return $this->storage->getPermissions($this->findPathToUse($path)); } - public function file_exists($path): bool { + public function file_exists(string $path): bool { return $this->storage->file_exists($this->findPathToUse($path)); } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { return $this->storage->filemtime($this->findPathToUse($path)); } - public function file_get_contents($path): string|false { + public function file_get_contents(string $path): string|false { return $this->storage->file_get_contents($this->findPathToUse($path)); } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { return $this->storage->file_put_contents($this->findPathToUse($path), $data); } - public function unlink($path): bool { + public function unlink(string $path): bool { $result = $this->storage->unlink($this->findPathToUse($path)); if ($result) { unset($this->namesCache[$path]); @@ -194,16 +189,16 @@ class Encoding extends Wrapper { return $result; } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { // second name always NFC return $this->storage->rename($this->findPathToUse($source), $this->findPathToUse($target)); } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { return $this->storage->copy($this->findPathToUse($source), $this->findPathToUse($target)); } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $result = $this->storage->fopen($this->findPathToUse($path), $mode); if ($result && $mode !== 'r' && $mode !== 'rb') { unset($this->namesCache[$path]); @@ -211,49 +206,49 @@ class Encoding extends Wrapper { return $result; } - public function getMimeType($path): string|false { + public function getMimeType(string $path): string|false { return $this->storage->getMimeType($this->findPathToUse($path)); } - public function hash($type, $path, $raw = false): string|false { + public function hash(string $type, string $path, bool $raw = false): string|false { return $this->storage->hash($type, $this->findPathToUse($path), $raw); } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { return $this->storage->free_space($this->findPathToUse($path)); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { return $this->storage->touch($this->findPathToUse($path), $mtime); } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { return $this->storage->getLocalFile($this->findPathToUse($path)); } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { return $this->storage->hasUpdated($this->findPathToUse($path), $time); } - public function getCache($path = '', $storage = null): \OCP\Files\Cache\ICache { + public function getCache(string $path = '', ?IStorage $storage = null): \OCP\Files\Cache\ICache { if (!$storage) { $storage = $this; } return $this->storage->getCache($this->findPathToUse($path), $storage); } - public function getScanner($path = '', $storage = null): IScanner { + public function getScanner(string $path = '', ?IStorage $storage = null): IScanner { if (!$storage) { $storage = $this; } return $this->storage->getScanner($this->findPathToUse($path), $storage); } - public function getETag($path): string|false { + public function getETag(string $path): string|false { return $this->storage->getETag($this->findPathToUse($path)); } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath)); } @@ -265,7 +260,7 @@ class Encoding extends Wrapper { return $result; } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($sourceStorage === $this) { $result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath)); if ($result) { @@ -283,13 +278,13 @@ class Encoding extends Wrapper { return $result; } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { $entry = $this->storage->getMetaData($this->findPathToUse($path)); $entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/'); return $entry; } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { $entries = $this->storage->getDirectoryContent($this->findPathToUse($directory)); foreach ($entries as $entry) { $entry['name'] = trim(Filesystem::normalizePath($entry['name']), '/'); diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index a4e8a571f42..a29e985377b 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -59,7 +59,7 @@ class Encryption extends Wrapper { parent::__construct($parameters); } - public function filesize($path): int|float|false { + public function filesize(string $path): int|float|false { $fullPath = $this->getFullPath($path); $info = $this->getCache()->get($path); @@ -102,11 +102,6 @@ class Encryption extends Wrapper { return $this->storage->filesize($path); } - /** - * @param string $path - * @param array $data - * @return array - */ private function modifyMetaData(string $path, array $data): array { $fullPath = $this->getFullPath($path); $info = $this->getCache()->get($path); @@ -130,7 +125,7 @@ class Encryption extends Wrapper { return $data; } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { $data = $this->storage->getMetaData($path); if (is_null($data)) { return null; @@ -138,14 +133,14 @@ class Encryption extends Wrapper { return $this->modifyMetaData($path, $data); } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { $parent = rtrim($directory, '/'); foreach ($this->getWrapperStorage()->getDirectoryContent($directory) as $data) { yield $this->modifyMetaData($parent . '/' . $data['name'], $data); } } - public function file_get_contents($path): string|false { + public function file_get_contents(string $path): string|false { $encryptionModule = $this->getEncryptionModule($path); if ($encryptionModule) { @@ -160,7 +155,7 @@ class Encryption extends Wrapper { return $this->storage->file_get_contents($path); } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { // file put content will always be translated to a stream write $handle = $this->fopen($path, 'w'); if (is_resource($handle)) { @@ -172,7 +167,7 @@ class Encryption extends Wrapper { return false; } - public function unlink($path): bool { + public function unlink(string $path): bool { $fullPath = $this->getFullPath($path); if ($this->util->isExcluded($fullPath)) { return $this->storage->unlink($path); @@ -186,7 +181,7 @@ class Encryption extends Wrapper { return $this->storage->unlink($path); } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $result = $this->storage->rename($source, $target); if ($result && @@ -211,7 +206,7 @@ class Encryption extends Wrapper { return $result; } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $result = $this->storage->rmdir($path); $fullPath = $this->getFullPath($path); if ($result && @@ -224,7 +219,7 @@ class Encryption extends Wrapper { return $result; } - public function isReadable($path): bool { + public function isReadable(string $path): bool { $isReadable = true; $metaData = $this->getMetaData($path); @@ -241,7 +236,7 @@ class Encryption extends Wrapper { return $this->storage->isReadable($path) && $isReadable; } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { $sourcePath = $this->getFullPath($source); if ($this->util->isExcluded($sourcePath)) { @@ -254,7 +249,7 @@ class Encryption extends Wrapper { return $this->copyFromStorage($this, $source, $target); } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { // check if the file is stored in the array cache, this means that we // copy a file over to the versions folder, in this case we don't want to // decrypt it @@ -491,7 +486,7 @@ class Encryption extends Wrapper { * This is required as stream_read only returns smaller chunks of data when the stream fetches from a * remote storage over the internet and it does not care about the given $blockSize. * - * @param handle the stream to read from + * @param resource $handle the stream to read from * @param int $blockSize Length of requested data block in bytes * @return string Data fetched from stream. */ @@ -511,8 +506,8 @@ class Encryption extends Wrapper { public function moveFromStorage( Storage\IStorage $sourceStorage, - $sourceInternalPath, - $targetInternalPath, + string $sourceInternalPath, + string $targetInternalPath, $preserveMtime = true, ): bool { if ($sourceStorage === $this) { @@ -542,8 +537,8 @@ class Encryption extends Wrapper { public function copyFromStorage( Storage\IStorage $sourceStorage, - $sourceInternalPath, - $targetInternalPath, + string $sourceInternalPath, + string $targetInternalPath, $preserveMtime = false, $isRename = false, ): bool { @@ -558,19 +553,13 @@ class Encryption extends Wrapper { /** * Update the encrypted cache version in the database - * - * @param Storage\IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @param bool $isRename - * @param bool $keepEncryptionVersion */ private function updateEncryptedVersion( Storage\IStorage $sourceStorage, - $sourceInternalPath, - $targetInternalPath, - $isRename, - $keepEncryptionVersion, + string $sourceInternalPath, + string $targetInternalPath, + bool $isRename, + bool $keepEncryptionVersion, ): void { $isEncrypted = $this->encryptionManager->isEnabled() && $this->shouldEncrypt($targetInternalPath); $cacheInformation = [ @@ -611,21 +600,14 @@ class Encryption extends Wrapper { /** * copy file between two storages - * - * @param Storage\IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @param bool $preserveMtime - * @param bool $isRename - * @return bool * @throws \Exception */ private function copyBetweenStorage( Storage\IStorage $sourceStorage, - $sourceInternalPath, - $targetInternalPath, - $preserveMtime, - $isRename, + string $sourceInternalPath, + string $targetInternalPath, + bool $preserveMtime, + bool $isRename, ): bool { // for versions we have nothing to do, because versions should always use the // key from the original file. Just create a 1:1 copy and done @@ -704,7 +686,7 @@ class Encryption extends Wrapper { return (bool)$result; } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { if ($this->encryptionManager->isEnabled()) { $cachedFile = $this->getCachedFile($path); if (is_string($cachedFile)) { @@ -721,7 +703,7 @@ class Encryption extends Wrapper { return $this->storage->isLocal(); } - public function stat($path): array|false { + public function stat(string $path): array|false { $stat = $this->storage->stat($path); if (!$stat) { return false; @@ -733,7 +715,7 @@ class Encryption extends Wrapper { return $stat; } - public function hash($type, $path, $raw = false): string|false { + public function hash(string $type, string $path, bool $raw = false): string|false { $fh = $this->fopen($path, 'rb'); $ctx = hash_init($type); hash_update_stream($ctx, $fh); @@ -747,18 +729,15 @@ class Encryption extends Wrapper { * @param string $path relative to mount point * @return string full path including mount point */ - protected function getFullPath($path): string { + protected function getFullPath(string $path): string { return Filesystem::normalizePath($this->mountPoint . '/' . $path); } /** * read first block of encrypted file, typically this will contain the * encryption header - * - * @param string $path - * @return string */ - protected function readFirstBlock($path): string { + protected function readFirstBlock(string $path): string { $firstBlock = ''; if ($this->storage->is_file($path)) { $handle = $this->storage->fopen($path, 'r'); @@ -770,11 +749,8 @@ class Encryption extends Wrapper { /** * return header size of given file - * - * @param string $path - * @return int */ - protected function getHeaderSize($path): int { + protected function getHeaderSize(string $path): int { $headerSize = 0; $realFile = $this->util->stripPartialFileExtension($path); if ($this->storage->is_file($realFile)) { @@ -791,11 +767,8 @@ class Encryption extends Wrapper { /** * read header from file - * - * @param string $path - * @return array */ - protected function getHeader($path): array { + protected function getHeader(string $path): array { $realFile = $this->util->stripPartialFileExtension($path); $exists = $this->storage->is_file($realFile); if ($exists) { @@ -827,12 +800,10 @@ class Encryption extends Wrapper { /** * read encryption module needed to read/write the file located at $path * - * @param string $path - * @return null|\OCP\Encryption\IEncryptionModule * @throws ModuleDoesNotExistsException * @throws \Exception */ - protected function getEncryptionModule($path): ?\OCP\Encryption\IEncryptionModule { + protected function getEncryptionModule(string $path): ?\OCP\Encryption\IEncryptionModule { $encryptionModule = null; $header = $this->getHeader($path); $encryptionModuleId = $this->util->getEncryptionModuleId($header); @@ -848,11 +819,7 @@ class Encryption extends Wrapper { return $encryptionModule; } - /** - * @param string $path - * @param int $unencryptedSize - */ - public function updateUnencryptedSize($path, $unencryptedSize): void { + public function updateUnencryptedSize(string $path, int|float $unencryptedSize): void { $this->unencryptedSize[$path] = $unencryptedSize; } @@ -861,9 +828,8 @@ class Encryption extends Wrapper { * * @param string $source path relative to data/ * @param string $target path relative to data/ - * @return bool */ - protected function copyKeys($source, $target): bool { + protected function copyKeys(string $source, string $target): bool { if (!$this->util->isExcluded($source)) { return $this->keyStorage->copyKeys($source, $target); } @@ -873,22 +839,16 @@ class Encryption extends Wrapper { /** * check if path points to a files version - * - * @param $path - * @return bool */ - protected function isVersion($path): bool { + protected function isVersion(string $path): bool { $normalized = Filesystem::normalizePath($path); return substr($normalized, 0, strlen('/files_versions/')) === '/files_versions/'; } /** * check if the given storage should be encrypted or not - * - * @param $path - * @return bool */ - protected function shouldEncrypt($path): bool { + protected function shouldEncrypt(string $path): bool { $fullPath = $this->getFullPath($path); $mountPointConfig = $this->mount->getOption('encrypt', true); if ($mountPointConfig === false) { @@ -930,9 +890,6 @@ class Encryption extends Wrapper { /** * Allow temporarily disabling the wrapper - * - * @param bool $enabled - * @return void */ public function setEnabled(bool $enabled): void { $this->enabled = $enabled; diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 256d669ede7..a85f59b87eb 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -40,7 +40,7 @@ class Jail extends Wrapper { $this->rootPath = $arguments['root']; } - public function getUnjailedPath($path): string { + public function getUnjailedPath(string $path): string { return trim(Filesystem::normalizePath($this->rootPath . '/' . $path), '/'); } @@ -52,7 +52,7 @@ class Jail extends Wrapper { } - public function getJailedPath($path): ?string { + public function getJailedPath(string $path): ?string { $root = rtrim($this->rootPath, '/') . '/'; if ($path !== $this->rootPath && !str_starts_with($path, $root)) { @@ -67,176 +67,174 @@ class Jail extends Wrapper { return parent::getId(); } - public function mkdir($path): bool { + public function mkdir(string $path): bool { return $this->getWrapperStorage()->mkdir($this->getUnjailedPath($path)); } - public function rmdir($path): bool { + public function rmdir(string $path): bool { return $this->getWrapperStorage()->rmdir($this->getUnjailedPath($path)); } - public function opendir($path) { + public function opendir(string $path) { return $this->getWrapperStorage()->opendir($this->getUnjailedPath($path)); } - public function is_dir($path): bool { + public function is_dir(string $path): bool { return $this->getWrapperStorage()->is_dir($this->getUnjailedPath($path)); } - public function is_file($path): bool { + public function is_file(string $path): bool { return $this->getWrapperStorage()->is_file($this->getUnjailedPath($path)); } - public function stat($path): array|false { + public function stat(string $path): array|false { return $this->getWrapperStorage()->stat($this->getUnjailedPath($path)); } - public function filetype($path): string|false { + public function filetype(string $path): string|false { return $this->getWrapperStorage()->filetype($this->getUnjailedPath($path)); } - public function filesize($path): int|float|false { + public function filesize(string $path): int|float|false { return $this->getWrapperStorage()->filesize($this->getUnjailedPath($path)); } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { return $this->getWrapperStorage()->isCreatable($this->getUnjailedPath($path)); } - public function isReadable($path): bool { + public function isReadable(string $path): bool { return $this->getWrapperStorage()->isReadable($this->getUnjailedPath($path)); } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return $this->getWrapperStorage()->isUpdatable($this->getUnjailedPath($path)); } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { return $this->getWrapperStorage()->isDeletable($this->getUnjailedPath($path)); } - public function isSharable($path): bool { + public function isSharable(string $path): bool { return $this->getWrapperStorage()->isSharable($this->getUnjailedPath($path)); } - public function getPermissions($path): int { + public function getPermissions(string $path): int { return $this->getWrapperStorage()->getPermissions($this->getUnjailedPath($path)); } - public function file_exists($path): bool { + public function file_exists(string $path): bool { return $this->getWrapperStorage()->file_exists($this->getUnjailedPath($path)); } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { return $this->getWrapperStorage()->filemtime($this->getUnjailedPath($path)); } - public function file_get_contents($path): string|false { + public function file_get_contents(string $path): string|false { return $this->getWrapperStorage()->file_get_contents($this->getUnjailedPath($path)); } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { return $this->getWrapperStorage()->file_put_contents($this->getUnjailedPath($path), $data); } - public function unlink($path): bool { + public function unlink(string $path): bool { return $this->getWrapperStorage()->unlink($this->getUnjailedPath($path)); } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { return $this->getWrapperStorage()->rename($this->getUnjailedPath($source), $this->getUnjailedPath($target)); } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { return $this->getWrapperStorage()->copy($this->getUnjailedPath($source), $this->getUnjailedPath($target)); } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { return $this->getWrapperStorage()->fopen($this->getUnjailedPath($path), $mode); } - public function getMimeType($path): string|false { + public function getMimeType(string $path): string|false { return $this->getWrapperStorage()->getMimeType($this->getUnjailedPath($path)); } - public function hash($type, $path, $raw = false): string|false { + public function hash(string $type, string $path, bool $raw = false): string|false { return $this->getWrapperStorage()->hash($type, $this->getUnjailedPath($path), $raw); } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { return $this->getWrapperStorage()->free_space($this->getUnjailedPath($path)); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { return $this->getWrapperStorage()->touch($this->getUnjailedPath($path), $mtime); } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { return $this->getWrapperStorage()->getLocalFile($this->getUnjailedPath($path)); } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { return $this->getWrapperStorage()->hasUpdated($this->getUnjailedPath($path), $time); } - public function getCache($path = '', $storage = null): ICache { + public function getCache(string $path = '', ?IStorage $storage = null): ICache { $sourceCache = $this->getWrapperStorage()->getCache($this->getUnjailedPath($path)); return new CacheJail($sourceCache, $this->rootPath); } - public function getOwner($path): string|false { + public function getOwner(string $path): string|false { return $this->getWrapperStorage()->getOwner($this->getUnjailedPath($path)); } - public function getWatcher($path = '', $storage = null): IWatcher { + public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher { $sourceWatcher = $this->getWrapperStorage()->getWatcher($this->getUnjailedPath($path), $this->getWrapperStorage()); return new JailWatcher($sourceWatcher, $this->rootPath); } - public function getETag($path): string|false { + public function getETag(string $path): string|false { return $this->getWrapperStorage()->getETag($this->getUnjailedPath($path)); } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { return $this->getWrapperStorage()->getMetaData($this->getUnjailedPath($path)); } - public function acquireLock($path, $type, ILockingProvider $provider): void { + public function acquireLock(string $path, int $type, ILockingProvider $provider): void { $this->getWrapperStorage()->acquireLock($this->getUnjailedPath($path), $type, $provider); } - public function releaseLock($path, $type, ILockingProvider $provider): void { + public function releaseLock(string $path, int $type, ILockingProvider $provider): void { $this->getWrapperStorage()->releaseLock($this->getUnjailedPath($path), $type, $provider); } - public function changeLock($path, $type, ILockingProvider $provider): void { + public function changeLock(string $path, int $type, ILockingProvider $provider): void { $this->getWrapperStorage()->changeLock($this->getUnjailedPath($path), $type, $provider); } /** * Resolve the path for the source of the share - * - * @param string $path */ - public function resolvePath($path): array { + public function resolvePath(string $path): array { return [$this->getWrapperStorage(), $this->getUnjailedPath($path)]; } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath)); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $this->getUnjailedPath($targetInternalPath)); } - public function getPropagator($storage = null): IPropagator { + public function getPropagator(?IStorage $storage = null): IPropagator { if (isset($this->propagator)) { return $this->propagator; } @@ -262,7 +260,7 @@ class Jail extends Wrapper { } } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { return $this->getWrapperStorage()->getDirectoryContent($this->getUnjailedPath($directory)); } } diff --git a/lib/private/Files/Storage/Wrapper/KnownMtime.php b/lib/private/Files/Storage/Wrapper/KnownMtime.php index 8d9349523c5..37454bdad17 100644 --- a/lib/private/Files/Storage/Wrapper/KnownMtime.php +++ b/lib/private/Files/Storage/Wrapper/KnownMtime.php @@ -26,7 +26,7 @@ class KnownMtime extends Wrapper { $this->clock = $arguments['clock']; } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { $result = parent::file_put_contents($path, $data); if ($result) { $now = $this->clock->now()->getTimestamp(); @@ -35,7 +35,7 @@ class KnownMtime extends Wrapper { return $result; } - public function stat($path): array|false { + public function stat(string $path): array|false { $stat = parent::stat($path); if ($stat) { $this->applyKnownMtime($path, $stat); @@ -43,7 +43,7 @@ class KnownMtime extends Wrapper { return $stat; } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { $stat = parent::getMetaData($path); if ($stat) { $this->applyKnownMtime($path, $stat); @@ -58,12 +58,12 @@ class KnownMtime extends Wrapper { } } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { $knownMtime = $this->knowMtimes->get($path) ?? 0; return max(parent::filemtime($path), $knownMtime); } - public function mkdir($path): bool { + public function mkdir(string $path): bool { $result = parent::mkdir($path); if ($result) { $this->knowMtimes->set($path, $this->clock->now()->getTimestamp()); @@ -71,7 +71,7 @@ class KnownMtime extends Wrapper { return $result; } - public function rmdir($path): bool { + public function rmdir(string $path): bool { $result = parent::rmdir($path); if ($result) { $this->knowMtimes->set($path, $this->clock->now()->getTimestamp()); @@ -79,7 +79,7 @@ class KnownMtime extends Wrapper { return $result; } - public function unlink($path): bool { + public function unlink(string $path): bool { $result = parent::unlink($path); if ($result) { $this->knowMtimes->set($path, $this->clock->now()->getTimestamp()); @@ -87,7 +87,7 @@ class KnownMtime extends Wrapper { return $result; } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { $result = parent::rename($source, $target); if ($result) { $this->knowMtimes->set($target, $this->clock->now()->getTimestamp()); @@ -96,7 +96,7 @@ class KnownMtime extends Wrapper { return $result; } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { $result = parent::copy($source, $target); if ($result) { $this->knowMtimes->set($target, $this->clock->now()->getTimestamp()); @@ -104,7 +104,7 @@ class KnownMtime extends Wrapper { return $result; } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { $result = parent::fopen($path, $mode); if ($result && $mode === 'w') { $this->knowMtimes->set($path, $this->clock->now()->getTimestamp()); @@ -112,7 +112,7 @@ class KnownMtime extends Wrapper { return $result; } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { $result = parent::touch($path, $mtime); if ($result) { $this->knowMtimes->set($path, $mtime ?? $this->clock->now()->getTimestamp()); @@ -120,7 +120,7 @@ class KnownMtime extends Wrapper { return $result; } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { $result = parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); if ($result) { $this->knowMtimes->set($targetInternalPath, $this->clock->now()->getTimestamp()); @@ -128,7 +128,7 @@ class KnownMtime extends Wrapper { return $result; } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { $result = parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); if ($result) { $this->knowMtimes->set($targetInternalPath, $this->clock->now()->getTimestamp()); diff --git a/lib/private/Files/Storage/Wrapper/PermissionsMask.php b/lib/private/Files/Storage/Wrapper/PermissionsMask.php index e4194a82e36..aed37bc27ba 100644 --- a/lib/private/Files/Storage/Wrapper/PermissionsMask.php +++ b/lib/private/Files/Storage/Wrapper/PermissionsMask.php @@ -9,6 +9,7 @@ namespace OC\Files\Storage\Wrapper; use OC\Files\Cache\Wrapper\CachePermissionsMask; use OCP\Constants; +use OCP\Files\Storage\IStorage; /** * Mask the permissions of a storage @@ -34,31 +35,31 @@ class PermissionsMask extends Wrapper { $this->mask = $arguments['mask']; } - private function checkMask($permissions): bool { + private function checkMask(int $permissions): bool { return ($this->mask & $permissions) === $permissions; } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); } - public function isSharable($path): bool { + public function isSharable(string $path): bool { return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); } - public function getPermissions($path): int { + public function getPermissions(string $path): int { return $this->storage->getPermissions($path) & $this->mask; } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { //This is a rename of the transfer file to the original file if (dirname($source) === dirname($target) && strpos($source, '.ocTransferId') > 0) { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::rename($source, $target); @@ -66,33 +67,33 @@ class PermissionsMask extends Wrapper { return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::rename($source, $target); } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::copy($source, $target); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; return $this->checkMask($permissions) and parent::touch($path, $mtime); } - public function mkdir($path): bool { + public function mkdir(string $path): bool { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::mkdir($path); } - public function rmdir($path): bool { + public function rmdir(string $path): bool { return $this->checkMask(Constants::PERMISSION_DELETE) and parent::rmdir($path); } - public function unlink($path): bool { + public function unlink(string $path): bool { return $this->checkMask(Constants::PERMISSION_DELETE) and parent::unlink($path); } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; return $this->checkMask($permissions) ? parent::file_put_contents($path, $data) : false; } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { if ($mode === 'r' or $mode === 'rb') { return parent::fopen($path, $mode); } else { @@ -101,7 +102,7 @@ class PermissionsMask extends Wrapper { } } - public function getCache($path = '', $storage = null): \OCP\Files\Cache\ICache { + public function getCache(string $path = '', ?IStorage $storage = null): \OCP\Files\Cache\ICache { if (!$storage) { $storage = $this; } @@ -109,7 +110,7 @@ class PermissionsMask extends Wrapper { return new CachePermissionsMask($sourceCache, $this->mask); } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { $data = parent::getMetaData($path); if ($data && isset($data['permissions'])) { @@ -119,14 +120,14 @@ class PermissionsMask extends Wrapper { return $data; } - public function getScanner($path = '', $storage = null): \OCP\Files\Cache\IScanner { + public function getScanner(string $path = '', ?IStorage $storage = null): \OCP\Files\Cache\IScanner { if (!$storage) { $storage = $this->storage; } return parent::getScanner($path, $storage); } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { foreach ($this->getWrapperStorage()->getDirectoryContent($directory) as $data) { $data['scan_permissions'] = $data['scan_permissions'] ?? $data['permissions']; $data['permissions'] &= $this->mask; diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index 9adc4685d34..42fa6308e70 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -49,11 +49,7 @@ class Quota extends Wrapper { return $this->getQuota() !== FileInfo::SPACE_UNLIMITED; } - /** - * @param string $path - * @param IStorage $storage - */ - protected function getSize($path, $storage = null): int|float { + protected function getSize(string $path, ?IStorage $storage = null): int|float { if ($this->quotaIncludeExternalStorage) { $rootInfo = Filesystem::getFileInfo('', 'ext'); if ($rootInfo) { @@ -71,7 +67,7 @@ class Quota extends Wrapper { } } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { if (!$this->hasQuota()) { return $this->storage->free_space($path); } @@ -91,7 +87,7 @@ class Quota extends Wrapper { } } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { if (!$this->hasQuota()) { return $this->storage->file_put_contents($path, $data); } @@ -103,7 +99,7 @@ class Quota extends Wrapper { } } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { if (!$this->hasQuota()) { return $this->storage->copy($source, $target); } @@ -115,7 +111,7 @@ class Quota extends Wrapper { } } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { if (!$this->hasQuota()) { return $this->storage->fopen($path, $mode); } @@ -141,7 +137,7 @@ class Quota extends Wrapper { * @param string $path Path that may identify a .part file * @note this is needed for reusing keys */ - private function isPartFile($path): bool { + private function isPartFile(string $path): bool { $extension = pathinfo($path, PATHINFO_EXTENSION); return ($extension === 'part'); @@ -154,7 +150,7 @@ class Quota extends Wrapper { return str_starts_with(ltrim($path, '/'), 'files/'); } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if (!$this->hasQuota()) { return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } @@ -166,7 +162,7 @@ class Quota extends Wrapper { } } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if (!$this->hasQuota()) { return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } @@ -178,7 +174,7 @@ class Quota extends Wrapper { } } - public function mkdir($path): bool { + public function mkdir(string $path): bool { if (!$this->hasQuota()) { return $this->storage->mkdir($path); } @@ -190,7 +186,7 @@ class Quota extends Wrapper { return parent::mkdir($path); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { if (!$this->hasQuota()) { return $this->storage->touch($path, $mtime); } diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 903f6e5e470..e1edbab95c6 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -54,151 +54,151 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return $this->getWrapperStorage()->getId(); } - public function mkdir($path): bool { + public function mkdir(string $path): bool { return $this->getWrapperStorage()->mkdir($path); } - public function rmdir($path): bool { + public function rmdir(string $path): bool { return $this->getWrapperStorage()->rmdir($path); } - public function opendir($path) { + public function opendir(string $path) { return $this->getWrapperStorage()->opendir($path); } - public function is_dir($path): bool { + public function is_dir(string $path): bool { return $this->getWrapperStorage()->is_dir($path); } - public function is_file($path): bool { + public function is_file(string $path): bool { return $this->getWrapperStorage()->is_file($path); } - public function stat($path): array|false { + public function stat(string $path): array|false { return $this->getWrapperStorage()->stat($path); } - public function filetype($path): string|false { + public function filetype(string $path): string|false { return $this->getWrapperStorage()->filetype($path); } - public function filesize($path): int|float|false { + public function filesize(string $path): int|float|false { return $this->getWrapperStorage()->filesize($path); } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { return $this->getWrapperStorage()->isCreatable($path); } - public function isReadable($path): bool { + public function isReadable(string $path): bool { return $this->getWrapperStorage()->isReadable($path); } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return $this->getWrapperStorage()->isUpdatable($path); } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { return $this->getWrapperStorage()->isDeletable($path); } - public function isSharable($path): bool { + public function isSharable(string $path): bool { return $this->getWrapperStorage()->isSharable($path); } - public function getPermissions($path): int { + public function getPermissions(string $path): int { return $this->getWrapperStorage()->getPermissions($path); } - public function file_exists($path): bool { + public function file_exists(string $path): bool { return $this->getWrapperStorage()->file_exists($path); } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { return $this->getWrapperStorage()->filemtime($path); } - public function file_get_contents($path): string|false { + public function file_get_contents(string $path): string|false { return $this->getWrapperStorage()->file_get_contents($path); } - public function file_put_contents($path, $data): int|float|false { + public function file_put_contents(string $path, mixed $data): int|float|false { return $this->getWrapperStorage()->file_put_contents($path, $data); } - public function unlink($path): bool { + public function unlink(string $path): bool { return $this->getWrapperStorage()->unlink($path); } - public function rename($source, $target): bool { + public function rename(string $source, string $target): bool { return $this->getWrapperStorage()->rename($source, $target); } - public function copy($source, $target): bool { + public function copy(string $source, string $target): bool { return $this->getWrapperStorage()->copy($source, $target); } - public function fopen($path, $mode) { + public function fopen(string $path, string $mode) { return $this->getWrapperStorage()->fopen($path, $mode); } - public function getMimeType($path): string|false { + public function getMimeType(string $path): string|false { return $this->getWrapperStorage()->getMimeType($path); } - public function hash($type, $path, $raw = false): string|false { + public function hash(string $type, string $path, bool $raw = false): string|false { return $this->getWrapperStorage()->hash($type, $path, $raw); } - public function free_space($path): int|float|false { + public function free_space(string $path): int|float|false { return $this->getWrapperStorage()->free_space($path); } - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { return $this->getWrapperStorage()->touch($path, $mtime); } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { return $this->getWrapperStorage()->getLocalFile($path); } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { return $this->getWrapperStorage()->hasUpdated($path, $time); } - public function getCache($path = '', $storage = null): ICache { + public function getCache(string $path = '', ?IStorage $storage = null): ICache { if (!$storage) { $storage = $this; } return $this->getWrapperStorage()->getCache($path, $storage); } - public function getScanner($path = '', $storage = null): IScanner { + public function getScanner(string $path = '', ?IStorage $storage = null): IScanner { if (!$storage) { $storage = $this; } return $this->getWrapperStorage()->getScanner($path, $storage); } - public function getOwner($path): string|false { + public function getOwner(string $path): string|false { return $this->getWrapperStorage()->getOwner($path); } - public function getWatcher($path = '', $storage = null): IWatcher { + public function getWatcher(string $path = '', ?IStorage $storage = null): IWatcher { if (!$storage) { $storage = $this; } return $this->getWrapperStorage()->getWatcher($path, $storage); } - public function getPropagator($storage = null): IPropagator { + public function getPropagator(?IStorage $storage = null): IPropagator { if (!$storage) { $storage = $this; } return $this->getWrapperStorage()->getPropagator($storage); } - public function getUpdater($storage = null): IUpdater { + public function getUpdater(?IStorage $storage = null): IUpdater { if (!$storage) { $storage = $this; } @@ -209,7 +209,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return $this->getWrapperStorage()->getStorageCache(); } - public function getETag($path): string|false { + public function getETag(string $path): string|false { return $this->getWrapperStorage()->getETag($path); } @@ -221,7 +221,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return $this->getWrapperStorage()->isLocal(); } - public function instanceOfStorage($class): bool { + public function instanceOfStorage(string $class): bool { if (ltrim($class, '\\') === 'OC\Files\Storage\Shared') { // FIXME Temporary fix to keep existing checks working $class = '\OCA\Files_Sharing\SharedStorage'; @@ -251,15 +251,13 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea /** * Pass any methods custom to specific storage implementations to the wrapped storage * - * @param string $method - * @param array $args * @return mixed */ - public function __call($method, $args) { + public function __call(string $method, array $args) { return call_user_func_array([$this->getWrapperStorage(), $method], $args); } - public function getDirectDownload($path): array|false { + public function getDirectDownload(string $path): array|false { return $this->getWrapperStorage()->getDirectDownload($path); } @@ -267,15 +265,15 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return $this->getWrapperStorage()->getAvailability(); } - public function setAvailability($isAvailable): void { + public function setAvailability(bool $isAvailable): void { $this->getWrapperStorage()->setAvailability($isAvailable); } - public function verifyPath($path, $fileName): void { + public function verifyPath(string $path, string $fileName): void { $this->getWrapperStorage()->verifyPath($path, $fileName); } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } @@ -283,7 +281,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return $this->getWrapperStorage()->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } @@ -291,23 +289,23 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return $this->getWrapperStorage()->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } - public function getMetaData($path): ?array { + public function getMetaData(string $path): ?array { return $this->getWrapperStorage()->getMetaData($path); } - public function acquireLock($path, $type, ILockingProvider $provider): void { + public function acquireLock(string $path, int $type, ILockingProvider $provider): void { if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { $this->getWrapperStorage()->acquireLock($path, $type, $provider); } } - public function releaseLock($path, $type, ILockingProvider $provider): void { + public function releaseLock(string $path, int $type, ILockingProvider $provider): void { if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { $this->getWrapperStorage()->releaseLock($path, $type, $provider); } } - public function changeLock($path, $type, ILockingProvider $provider): void { + public function changeLock(string $path, int $type, ILockingProvider $provider): void { if ($this->getWrapperStorage()->instanceOfStorage('\OCP\Files\Storage\ILockingStorage')) { $this->getWrapperStorage()->changeLock($path, $type, $provider); } @@ -331,7 +329,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea } } - public function getDirectoryContent($directory): \Traversable { + public function getDirectoryContent(string $directory): \Traversable { return $this->getWrapperStorage()->getDirectoryContent($directory); } diff --git a/lib/private/Lockdown/Filesystem/NullStorage.php b/lib/private/Lockdown/Filesystem/NullStorage.php index 48e2cef8e24..114ccade1bd 100644 --- a/lib/private/Lockdown/Filesystem/NullStorage.php +++ b/lib/private/Lockdown/Filesystem/NullStorage.php @@ -20,119 +20,119 @@ class NullStorage extends Common { return 'null'; } - public function mkdir($path): never { + public function mkdir(string $path): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function rmdir($path): never { + public function rmdir(string $path): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function opendir($path): IteratorDirectory { + public function opendir(string $path): IteratorDirectory { return new IteratorDirectory([]); } - public function is_dir($path): bool { + public function is_dir(string $path): bool { return $path === ''; } - public function is_file($path): bool { + public function is_file(string $path): bool { return false; } - public function stat($path): never { + public function stat(string $path): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function filetype($path): string|false { + public function filetype(string $path): string|false { return ($path === '') ? 'dir' : false; } - public function filesize($path): never { + public function filesize(string $path): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function isCreatable($path): bool { + public function isCreatable(string $path): bool { return false; } - public function isReadable($path): bool { + public function isReadable(string $path): bool { return $path === ''; } - public function isUpdatable($path): bool { + public function isUpdatable(string $path): bool { return false; } - public function isDeletable($path): bool { + public function isDeletable(string $path): bool { return false; } - public function isSharable($path): bool { + public function isSharable(string $path): bool { return false; } - public function getPermissions($path): int { + public function getPermissions(string $path): int { return 0; } - public function file_exists($path): bool { + public function file_exists(string $path): bool { return $path === ''; } - public function filemtime($path): int|false { + public function filemtime(string $path): int|false { return ($path === '') ? time() : false; } - public function file_get_contents($path): never { + public function file_get_contents(string $path): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function file_put_contents($path, $data): never { + public function file_put_contents(string $path, mixed $data): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function unlink($path): never { + public function unlink(string $path): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function rename($source, $target): never { + public function rename(string $source, string $target): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function copy($source, $target): never { + public function copy(string $source, string $target): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function fopen($path, $mode): never { + public function fopen(string $path, string $mode): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function getMimeType($path): never { + public function getMimeType(string $path): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function hash($type, $path, $raw = false): never { + public function hash(string $type, string $path, bool $raw = false): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function free_space($path): int { + public function free_space(string $path): int { return FileInfo::SPACE_UNKNOWN; } - public function touch($path, $mtime = null): never { + public function touch(string $path, ?int $mtime = null): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function getLocalFile($path): string|false { + public function getLocalFile(string $path): string|false { return false; } - public function hasUpdated($path, $time): bool { + public function hasUpdated(string $path, int $time): bool { return false; } - public function getETag($path): string { + public function getETag(string $path): string { return ''; } @@ -140,15 +140,15 @@ class NullStorage extends Common { return false; } - public function getDirectDownload($path): array|false { + public function getDirectDownload(string $path): array|false { return false; } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): never { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): never { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): never { throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); } @@ -156,11 +156,11 @@ class NullStorage extends Common { return true; } - public function getOwner($path): string|false { + public function getOwner(string $path): string|false { return false; } - public function getCache($path = '', $storage = null): ICache { + public function getCache(string $path = '', ?IStorage $storage = null): ICache { return new NullCache(); } } diff --git a/lib/public/Files/Storage/IChunkedFileWrite.php b/lib/public/Files/Storage/IChunkedFileWrite.php index 1095ee7cbfc..e166a7f3b1f 100644 --- a/lib/public/Files/Storage/IChunkedFileWrite.php +++ b/lib/public/Files/Storage/IChunkedFileWrite.php @@ -24,28 +24,19 @@ interface IChunkedFileWrite extends IStorage { public function startChunkedWrite(string $targetPath): string; /** - * @param string $targetPath - * @param string $writeToken - * @param string $chunkId * @param resource $data - * @param int|null $size * @throws GenericFileException * @since 26.0.0 */ public function putChunkedWritePart(string $targetPath, string $writeToken, string $chunkId, $data, ?int $size = null): ?array; /** - * @param string $targetPath - * @param string $writeToken - * @return int * @throws GenericFileException * @since 26.0.0 */ public function completeChunkedWrite(string $targetPath, string $writeToken): int; /** - * @param string $targetPath - * @param string $writeToken * @throws GenericFileException * @since 26.0.0 */ diff --git a/lib/public/Files/Storage/ILockingStorage.php b/lib/public/Files/Storage/ILockingStorage.php index abec7d91b83..ceedf33ceab 100644 --- a/lib/public/Files/Storage/ILockingStorage.php +++ b/lib/public/Files/Storage/ILockingStorage.php @@ -21,27 +21,24 @@ interface ILockingStorage { /** * @param string $path The path of the file to acquire the lock for * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider * @throws \OCP\Lock\LockedException * @since 9.0.0 */ - public function acquireLock($path, $type, ILockingProvider $provider); + public function acquireLock(string $path, int $type, ILockingProvider $provider); /** * @param string $path The path of the file to acquire the lock for * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider * @throws \OCP\Lock\LockedException * @since 9.0.0 */ - public function releaseLock($path, $type, ILockingProvider $provider); + public function releaseLock(string $path, int $type, ILockingProvider $provider); /** * @param string $path The path of the file to change the lock for * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider * @throws \OCP\Lock\LockedException * @since 9.0.0 */ - public function changeLock($path, $type, ILockingProvider $provider); + public function changeLock(string $path, int $type, ILockingProvider $provider); } diff --git a/lib/public/Files/Storage/INotifyStorage.php b/lib/public/Files/Storage/INotifyStorage.php index 8656f709116..0e5cf53af21 100644 --- a/lib/public/Files/Storage/INotifyStorage.php +++ b/lib/public/Files/Storage/INotifyStorage.php @@ -36,10 +36,9 @@ interface INotifyStorage { /** * Start the notification handler for this storage * - * @param $path * @return INotifyHandler * * @since 12.0.0 */ - public function notify($path); + public function notify(string $path); } diff --git a/lib/public/Files/Storage/ISharedStorage.php b/lib/public/Files/Storage/ISharedStorage.php index 836c4aefcdb..69fc60750c5 100644 --- a/lib/public/Files/Storage/ISharedStorage.php +++ b/lib/public/Files/Storage/ISharedStorage.php @@ -19,7 +19,6 @@ interface ISharedStorage extends IStorage { /** * The the associated share * - * @return IShare * @since 30.0.0 */ public function getShare(): IShare; diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index 924e91e8164..5f6c8a0e8a0 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -40,280 +40,243 @@ interface IStorage { * see https://www.php.net/manual/en/function.mkdir.php * implementations need to implement a recursive mkdir * - * @param string $path * @return bool * @since 9.0.0 */ - public function mkdir($path); + public function mkdir(string $path); /** * see https://www.php.net/manual/en/function.rmdir.php * - * @param string $path * @return bool * @since 9.0.0 */ - public function rmdir($path); + public function rmdir(string $path); /** * see https://www.php.net/manual/en/function.opendir.php * - * @param string $path * @return resource|false * @since 9.0.0 */ - public function opendir($path); + public function opendir(string $path); /** * see https://www.php.net/manual/en/function.is-dir.php * - * @param string $path * @return bool * @since 9.0.0 */ - public function is_dir($path); + public function is_dir(string $path); /** * see https://www.php.net/manual/en/function.is-file.php * - * @param string $path * @return bool * @since 9.0.0 */ - public function is_file($path); + public function is_file(string $path); /** * see https://www.php.net/manual/en/function.stat.php * only the following keys are required in the result: size and mtime * - * @param string $path * @return array|false * @since 9.0.0 */ - public function stat($path); + public function stat(string $path); /** * see https://www.php.net/manual/en/function.filetype.php * - * @param string $path * @return string|false * @since 9.0.0 */ - public function filetype($path); + public function filetype(string $path); /** * see https://www.php.net/manual/en/function.filesize.php * The result for filesize when called on a folder is required to be 0 * - * @param string $path * @return int|float|false * @since 9.0.0 */ - public function filesize($path); + public function filesize(string $path); /** * check if a file can be created in $path * - * @param string $path * @return bool * @since 9.0.0 */ - public function isCreatable($path); + public function isCreatable(string $path); /** * check if a file can be read * - * @param string $path * @return bool * @since 9.0.0 */ - public function isReadable($path); + public function isReadable(string $path); /** * check if a file can be written to * - * @param string $path * @return bool * @since 9.0.0 */ - public function isUpdatable($path); + public function isUpdatable(string $path); /** * check if a file can be deleted * - * @param string $path * @return bool * @since 9.0.0 */ - public function isDeletable($path); + public function isDeletable(string $path); /** * check if a file can be shared * - * @param string $path * @return bool * @since 9.0.0 */ - public function isSharable($path); + public function isSharable(string $path); /** * get the full permissions of a path. * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php * - * @param string $path * @return int * @since 9.0.0 */ - public function getPermissions($path); + public function getPermissions(string $path); /** - * see https://www.php.net/manual/en/function.file_exists.php + * see https://www.php.net/manual/en/function.file-exists.php * - * @param string $path * @return bool * @since 9.0.0 */ - public function file_exists($path); + public function file_exists(string $path); /** * see https://www.php.net/manual/en/function.filemtime.php * - * @param string $path * @return int|false * @since 9.0.0 */ - public function filemtime($path); + public function filemtime(string $path); /** - * see https://www.php.net/manual/en/function.file_get_contents.php + * see https://www.php.net/manual/en/function.file-get-contents.php * - * @param string $path * @return string|false * @since 9.0.0 */ - public function file_get_contents($path); + public function file_get_contents(string $path); /** - * see https://www.php.net/manual/en/function.file_put_contents.php + * see https://www.php.net/manual/en/function.file-put-contents.php * - * @param string $path - * @param mixed $data * @return int|float|false * @since 9.0.0 */ - public function file_put_contents($path, $data); + public function file_put_contents(string $path, mixed $data); /** * see https://www.php.net/manual/en/function.unlink.php * - * @param string $path * @return bool * @since 9.0.0 */ - public function unlink($path); + public function unlink(string $path); /** * see https://www.php.net/manual/en/function.rename.php * - * @param string $source - * @param string $target * @return bool * @since 9.0.0 */ - public function rename($source, $target); + public function rename(string $source, string $target); /** * see https://www.php.net/manual/en/function.copy.php * - * @param string $source - * @param string $target * @return bool * @since 9.0.0 */ - public function copy($source, $target); + public function copy(string $source, string $target); /** * see https://www.php.net/manual/en/function.fopen.php * - * @param string $path - * @param string $mode * @return resource|false * @since 9.0.0 */ - public function fopen($path, $mode); + public function fopen(string $path, string $mode); /** * get the mimetype for a file or folder * The mimetype for a folder is required to be "httpd/unix-directory" * - * @param string $path * @return string|false * @since 9.0.0 */ - public function getMimeType($path); + public function getMimeType(string $path); /** * see https://www.php.net/manual/en/function.hash-file.php * - * @param string $type - * @param string $path - * @param bool $raw * @return string|false * @since 9.0.0 */ - public function hash($type, $path, $raw = false); + public function hash(string $type, string $path, bool $raw = false); /** * see https://www.php.net/manual/en/function.disk-free-space.php * - * @param string $path * @return int|float|false * @since 9.0.0 */ - public function free_space($path); + public function free_space(string $path); /** * see https://www.php.net/manual/en/function.touch.php * If the backend does not support the operation, false should be returned * - * @param string $path - * @param int $mtime * @return bool * @since 9.0.0 */ - public function touch($path, $mtime = null); + public function touch(string $path, ?int $mtime = null); /** * get the path to a local version of the file. * The local version of the file can be temporary and doesn't have to be persistent across requests * - * @param string $path * @return string|false * @since 9.0.0 */ - public function getLocalFile($path); + public function getLocalFile(string $path); /** * check if a file or folder has been updated since $time * - * @param string $path - * @param int $time * @return bool * @since 9.0.0 * * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. * returning true for other changes in the folder is optional */ - public function hasUpdated($path, $time); + public function hasUpdated(string $path, int $time); /** * get the ETag for a file or folder * - * @param string $path * @return string|false * @since 9.0.0 */ - public function getETag($path); + public function getETag(string $path); /** * Returns whether the storage is local, which means that files @@ -331,51 +294,41 @@ interface IStorage { * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class * * @template T of IStorage - * @param string $class * @psalm-param class-string $class * @return bool * @since 9.0.0 * @psalm-assert-if-true T $this */ - public function instanceOfStorage($class); + public function instanceOfStorage(string $class); /** * A custom storage implementation can return an url for direct download of a give file. * * For now the returned array can hold the parameter url - in future more attributes might follow. * - * @param string $path * @return array|false * @since 9.0.0 */ - public function getDirectDownload($path); + public function getDirectDownload(string $path); /** - * @param string $path the path of the target folder - * @param string $fileName the name of the file itself * @return void * @throws InvalidPathException * @since 9.0.0 */ - public function verifyPath($path, $fileName); + public function verifyPath(string $path, string $fileName); /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath * @return bool * @since 9.0.0 */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath); + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath); /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath * @return bool * @since 9.0.0 */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath); + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath); /** * Test a storage for availability @@ -393,10 +346,9 @@ interface IStorage { /** * @since 9.0.0 - * @param bool $isAvailable * @return void */ - public function setAvailability($isAvailable); + public function setAvailability(bool $isAvailable); /** * @since 12.0.0 @@ -406,19 +358,16 @@ interface IStorage { public function needsPartFile(); /** - * @param string $path path for which to retrieve the owner * @return string|false * @since 9.0.0 */ - public function getOwner($path); + public function getOwner(string $path); /** - * @param string $path - * @param IStorage|null $storage * @return ICache * @since 9.0.0 */ - public function getCache($path = '', $storage = null); + public function getCache(string $path = '', ?IStorage $storage = null); /** * @return IPropagator @@ -450,7 +399,7 @@ interface IStorage { * This can be used for storages that do not have a dedicated owner, where we want to * pass the user that we setup the mountpoint for along to the storage layer * - * @param string|null $user Owner user id + * @param ?string $user Owner user id * @return void * @since 30.0.0 */ diff --git a/lib/public/Files/Storage/IStorageFactory.php b/lib/public/Files/Storage/IStorageFactory.php index 6d44b39274e..24f87d2e775 100644 --- a/lib/public/Files/Storage/IStorageFactory.php +++ b/lib/public/Files/Storage/IStorageFactory.php @@ -19,20 +19,15 @@ interface IStorageFactory { * * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage * - * @param string $wrapperName - * @param callable $callback * @return bool true if the wrapper was added, false if there was already a wrapper with this * name registered * @since 8.0.0 */ - public function addStorageWrapper($wrapperName, $callback); + public function addStorageWrapper(string $wrapperName, callable $callback); /** - * @param IMountPoint $mountPoint - * @param string $class - * @param array $arguments * @return IStorage * @since 8.0.0 */ - public function getInstance(IMountPoint $mountPoint, $class, $arguments); + public function getInstance(IMountPoint $mountPoint, string $class, array $arguments); } diff --git a/lib/public/Files/Storage/IWriteStreamStorage.php b/lib/public/Files/Storage/IWriteStreamStorage.php index 6da34563848..b03f46ef2bc 100644 --- a/lib/public/Files/Storage/IWriteStreamStorage.php +++ b/lib/public/Files/Storage/IWriteStreamStorage.php @@ -19,9 +19,8 @@ interface IWriteStreamStorage extends IStorage { /** * Write the data from a stream to a file * - * @param string $path * @param resource $stream - * @param int|null $size the size of the stream if known in advance + * @param ?int $size the size of the stream if known in advance * @return int the number of bytes written * @throws GenericFileException * @since 15.0.0 diff --git a/tests/lib/Files/Mount/MountPointTest.php b/tests/lib/Files/Mount/MountPointTest.php index 3de54e315a1..96987c9f5eb 100644 --- a/tests/lib/Files/Mount/MountPointTest.php +++ b/tests/lib/Files/Mount/MountPointTest.php @@ -8,11 +8,9 @@ namespace Test\Files\Mount; use OC\Files\Storage\StorageFactory; +use OC\Lockdown\Filesystem\NullStorage; use OCP\Files\Storage\IStorage; -class DummyStorage { -} - class MountPointTest extends \Test\TestCase { public function testGetStorage(): void { $storage = $this->createMock(IStorage::class); @@ -27,7 +25,7 @@ class MountPointTest extends \Test\TestCase { $mountPoint = new \OC\Files\Mount\MountPoint( // just use this because a real class is needed - '\Test\Files\Mount\DummyStorage', + NullStorage::class, '/mountpoint', null, $loader @@ -54,7 +52,7 @@ class MountPointTest extends \Test\TestCase { $mountPoint = new \OC\Files\Mount\MountPoint( // just use this because a real class is needed - '\Test\Files\Mount\DummyStorage', + NullStorage::class, '/mountpoint', null, $loader diff --git a/tests/lib/Files/Storage/CopyDirectoryTest.php b/tests/lib/Files/Storage/CopyDirectoryTest.php index c08bb6f6482..e434c6b787f 100644 --- a/tests/lib/Files/Storage/CopyDirectoryTest.php +++ b/tests/lib/Files/Storage/CopyDirectoryTest.php @@ -10,11 +10,11 @@ namespace Test\Files\Storage; use OC\Files\Storage\Temporary; class StorageNoRecursiveCopy extends Temporary { - public function copy($path1, $path2): bool { - if ($this->is_dir($path1)) { + public function copy(string $source, string $target): bool { + if ($this->is_dir($source)) { return false; } - return copy($this->getSourcePath($path1), $this->getSourcePath($path2)); + return copy($this->getSourcePath($source), $this->getSourcePath($target)); } } diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index e393476bd05..2a74558c70d 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -37,27 +37,27 @@ use Test\TestMoveableMountPoint; use Test\Traits\UserTrait; class TemporaryNoTouch extends Temporary { - public function touch($path, $mtime = null): bool { + public function touch(string $path, ?int $mtime = null): bool { return false; } } class TemporaryNoCross extends Temporary { - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = null): bool { + public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, bool $preserveMtime = false): bool { return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime); } - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { + public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } } class TemporaryNoLocal extends Temporary { - public function instanceOfStorage($className): bool { - if ($className === '\OC\Files\Storage\Local') { + public function instanceOfStorage(string $class): bool { + if ($class === '\OC\Files\Storage\Local') { return false; } else { - return parent::instanceOfStorage($className); + return parent::instanceOfStorage($class); } } } -- 2.39.5