From 294a6f8f6e270cf1f7b3cdff847845f519c325d9 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Thu, 26 Sep 2024 18:05:25 +0200 Subject: [PATCH 1/2] fix(psalm): Update stubs Signed-off-by: provokateurin --- psalm.xml | 1 + tests/stubs/oc_files_cache_cache.php | 2 +- ...c_files_objectstore_objectstorestorage.php | 43 +-- tests/stubs/oc_files_setupmanager.php | 1 + tests/stubs/oc_files_storage_common.php | 174 +++------ tests/stubs/oc_files_storage_local.php | 75 ++-- tests/stubs/oc_files_storage_storage.php | 49 +-- tests/stubs/oc_files_storage_temporary.php | 4 +- tests/stubs/oc_files_storage_wrapper_jail.php | 288 +++----------- ..._files_storage_wrapper_permissionsmask.php | 30 +- .../stubs/oc_files_storage_wrapper_quota.php | 59 +-- .../oc_files_storage_wrapper_wrapper.php | 364 +++--------------- tests/stubs/oc_server.php | 1 + ...cp_files_storage_iconstructablestorage.php | 28 ++ tests/stubs/test_testcase.php | 15 + 15 files changed, 296 insertions(+), 838 deletions(-) create mode 100644 tests/stubs/ocp_files_storage_iconstructablestorage.php diff --git a/psalm.xml b/psalm.xml index 359397355..cfb803ede 100644 --- a/psalm.xml +++ b/psalm.xml @@ -106,6 +106,7 @@ + diff --git a/tests/stubs/oc_files_cache_cache.php b/tests/stubs/oc_files_cache_cache.php index 9b2282a70..7647da6df 100644 --- a/tests/stubs/oc_files_cache_cache.php +++ b/tests/stubs/oc_files_cache_cache.php @@ -389,7 +389,7 @@ public function getPathById($id) * * @param int $id * @return array first element holding the storage id, second the path - * @deprecated use getPathById() instead + * @deprecated 17.0.0 use getPathById() instead */ public static function getById($id) { diff --git a/tests/stubs/oc_files_objectstore_objectstorestorage.php b/tests/stubs/oc_files_objectstore_objectstorestorage.php index 650b75947..e9c888a7e 100644 --- a/tests/stubs/oc_files_objectstore_objectstorestorage.php +++ b/tests/stubs/oc_files_objectstore_objectstorestorage.php @@ -17,6 +17,7 @@ use OC\Files\Storage\PolyFill\CopyDirectory; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Cache\IScanner; use OCP\Files\FileInfo; use OCP\Files\GenericFileException; use OCP\Files\NotFoundException; @@ -41,7 +42,7 @@ public function __construct($params) { } - public function mkdir($path, bool $force = false) + public function mkdir($path, bool $force = false): bool { } @@ -49,19 +50,19 @@ public function mkdir($path, bool $force = false) * 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) + public function getScanner($path = '', $storage = null): IScanner { } - public function getId() + public function getId(): string { } - public function rmdir($path) + public function rmdir($path): bool { } - public function unlink($path) + public function unlink($path): bool { } @@ -69,11 +70,11 @@ public function rmObject(ICacheEntry $entry): bool { } - public function stat($path) + public function stat($path): array|false { } - public function getPermissions($path) + public function getPermissions($path): int { } @@ -93,7 +94,7 @@ public function opendir($path) { } - public function filetype($path) + public function filetype($path): string|false { } @@ -101,19 +102,19 @@ public function fopen($path, $mode) { } - public function file_exists($path) + public function file_exists($path): bool { } - public function rename($source, $target) + public function rename($source, $target): bool { } - public function getMimeType($path) + public function getMimeType($path): string|false { } - public function touch($path, $mtime = null) + public function touch($path, $mtime = null): bool { } @@ -121,22 +122,15 @@ public function writeBack($tmpFile, $path) { } - /** - * external changes are not supported, exclusive access to the object storage is assumed - * - * @param string $path - * @param int $time - * @return false - */ - public function hasUpdated($path, $time) + public function hasUpdated($path, $time): bool { } - public function needsPartFile() + public function needsPartFile(): bool { } - public function file_put_contents($path, $data) + public function file_put_contents($path, $data): int { } @@ -148,7 +142,7 @@ public function getObjectStore(): IObjectStore { } - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool { } @@ -156,7 +150,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t { } - public function copy($source, $target) + public function copy($source, $target): bool { } @@ -165,7 +159,6 @@ public function startChunkedWrite(string $targetPath): string } /** - * * @throws GenericFileException */ public function putChunkedWritePart(string $targetPath, string $writeToken, string $chunkId, $data, $size = null): ?array diff --git a/tests/stubs/oc_files_setupmanager.php b/tests/stubs/oc_files_setupmanager.php index 83c40ff76..79917d66e 100644 --- a/tests/stubs/oc_files_setupmanager.php +++ b/tests/stubs/oc_files_setupmanager.php @@ -35,6 +35,7 @@ use OCP\Files\Config\IHomeMountProvider; use OCP\Files\Config\IMountProvider; use OCP\Files\Config\IUserMountCache; +use OCP\Files\Events\BeforeFileSystemSetupEvent; use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\Events\Node\FilesystemTornDownEvent; use OCP\Files\Mount\IMountManager; diff --git a/tests/stubs/oc_files_storage_common.php b/tests/stubs/oc_files_storage_common.php index 99df515d2..c4cefe6d2 100644 --- a/tests/stubs/oc_files_storage_common.php +++ b/tests/stubs/oc_files_storage_common.php @@ -17,10 +17,16 @@ use OC\Files\Filesystem; use OC\Files\Storage\Wrapper\Jail; use OC\Files\Storage\Wrapper\Wrapper; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IUpdater; +use OCP\Files\Cache\IWatcher; use OCP\Files\ForbiddenException; use OCP\Files\GenericFileException; use OCP\Files\IFilenameValidator; use OCP\Files\InvalidPathException; +use OCP\Files\Storage\IConstructableStorage; use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; @@ -41,7 +47,7 @@ * Some \OC\Files\Storage\Common methods call functions which are first defined * in classes which extend it, e.g. $this->stat() . */ -abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage { +abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage, IConstructableStorage { use LocalTempFileTrait; protected ?Cache $cache = null; @@ -61,102 +67,93 @@ public function __construct($parameters) { * Remove a file or folder * * @param string $path - * @return bool */ - protected function remove($path) + protected function remove($path): bool { } - public function is_dir($path) + public function is_dir($path): bool { } - public function is_file($path) + public function is_file($path): bool { } - public function filesize($path): false|int|float + public function filesize($path): int|float|false { } - public function isReadable($path) + public function isReadable($path): bool { } - public function isUpdatable($path) + public function isUpdatable($path): bool { } - public function isCreatable($path) + public function isCreatable($path): bool { } - public function isDeletable($path) + public function isDeletable($path): bool { } - public function isSharable($path) + public function isSharable($path): bool { } - public function getPermissions($path) + public function getPermissions($path): int { } - public function filemtime($path) + public function filemtime($path): int|false { } - public function file_get_contents($path) + public function file_get_contents($path): string|false { } - public function file_put_contents($path, $data) + public function file_put_contents($path, $data): int|float|false { } - public function rename($source, $target) + public function rename($source, $target): bool { } - public function copy($source, $target) + public function copy($source, $target): bool { } - public function getMimeType($path) + public function getMimeType($path): string|false { } - public function hash($type, $path, $raw = false) + public function hash($type, $path, $raw = false): string|false { } - public function getLocalFile($path) + public function getLocalFile($path): string|false { } - /** - * @param string $query - * @param string $dir - * @return array - */ - protected function searchInDir($query, $dir = '') + protected function searchInDir($query, $dir = ''): array { } /** + * @inheritDoc * Check if a file or folder has been updated since $time * * The method is only used to check if the cache needs to be updated. Storage backends that don't support checking * the mtime should always return false here. As a result storage implementations that always return false expect * exclusive access to the backend and will not pick up files that have been added in a way that circumvents * Nextcloud filesystem. - * - * @param string $path - * @param int $time - * @return bool */ - public function hasUpdated($path, $time) + public function hasUpdated($path, $time): bool { } @@ -164,36 +161,27 @@ protected function getCacheDependencies(): CacheDependencies { } - /** - * @return Cache - */ - public function getCache($path = '', $storage = null) + public function getCache($path = '', $storage = null): ICache { } - public function getScanner($path = '', $storage = null) + public function getScanner($path = '', $storage = null): IScanner { } - public function getWatcher($path = '', $storage = null) + public function getWatcher($path = '', $storage = null): IWatcher { } - public function getPropagator($storage = null) + public function getPropagator($storage = null): IPropagator { } - /** - * get a propagator instance for the cache - * - * @param \OC\Files\Storage\Storage $storage (optional) the storage to pass to the watcher - * @return Updater - */ - public function getUpdater($storage = null) + public function getUpdater($storage = null): IUpdater { } - public function getStorageCache($storage = null) + public function getStorageCache($storage = null): \OC\Files\Cache\Storage { } @@ -201,13 +189,7 @@ public function getOwner($path): string|false { } - /** - * get the ETag for a file or folder - * - * @param string $path - * @return string|false - */ - public function getETag($path) + public function getETag($path): string|false { } @@ -218,33 +200,22 @@ public function getETag($path) * @param string $path The path to clean * @return string cleaned path */ - public function cleanPath($path) + public function cleanPath($path): string { } /** * Test a storage for availability - * - * @return bool */ - public function test() + public function test(): bool { } - /** - * get the free space in the storage - * - * @param string $path - * @return int|float|false - */ - public function free_space($path) + public function free_space($path): int|float|false { } - /** - * {@inheritdoc} - */ - public function isLocal() + public function isLocal(): bool { } @@ -252,9 +223,8 @@ public function isLocal() * 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 - * @return bool */ - public function instanceOfStorage($class) + public function instanceOfStorage($class): bool { } @@ -264,17 +234,12 @@ public function instanceOfStorage($class) * For now the returned array can hold the parameter url - in future more attributes might follow. * * @param string $path - * @return array|false */ - public function getDirectDownload($path) + public function getDirectDownload($path): array|false { } - /** - * @inheritdoc - * @throws InvalidPathException - */ - public function verifyPath($path, $fileName) + public function verifyPath($path, $fileName): void { } @@ -286,106 +251,75 @@ protected function getFilenameValidator(): IFilenameValidator { } - /** - * @param array $options - */ - public function setMountOptions(array $options) + public function setMountOptions(array $options): void { } /** * @param string $name * @param mixed $default - * @return mixed */ - public function getMountOption($name, $default = null) + public function getMountOption($name, $default = null): mixed { } /** - * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @param bool $preserveMtime - * @return bool */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool { } /** - * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath - * @return bool */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { } - public function getMetaData($path) + public function getMetaData($path): ?array { } - public function acquireLock($path, $type, ILockingProvider $provider) + public function acquireLock($path, $type, ILockingProvider $provider): void { } - public function releaseLock($path, $type, ILockingProvider $provider) + public function releaseLock($path, $type, ILockingProvider $provider): void { } - public function changeLock($path, $type, ILockingProvider $provider) + public function changeLock($path, $type, ILockingProvider $provider): void { } /** * @return array [ available, last_checked ] */ - public function getAvailability() + public function getAvailability(): array { } - /** - * @param bool $isAvailable - */ - public function setAvailability($isAvailable) + public function setAvailability($isAvailable): void { } - /** - * Allow setting the storage owner - * - * 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 - * @return void - */ public function setOwner(?string $user): void { } - /** - * @return bool - */ - public function needsPartFile() + public function needsPartFile(): bool { } - /** - * fallback implementation - * - * @param string $path - * @param resource $stream - * @param int $size - * @return int - */ public function writeStream(string $path, $stream, ?int $size = null): int { } - public function getDirectoryContent($directory): \Traversable + public function getDirectoryContent($directory): \Traversable|false { } } diff --git a/tests/stubs/oc_files_storage_local.php b/tests/stubs/oc_files_storage_local.php index 00285ee10..66bacaa23 100644 --- a/tests/stubs/oc_files_storage_local.php +++ b/tests/stubs/oc_files_storage_local.php @@ -41,15 +41,15 @@ public function __construct($arguments) public function __destruct() { } - public function getId() + public function getId(): string { } - public function mkdir($path) + public function mkdir($path): bool { } - public function rmdir($path) + public function rmdir($path): bool { } @@ -57,59 +57,59 @@ public function opendir($path) { } - public function is_dir($path) + public function is_dir($path): bool { } - public function is_file($path) + public function is_file($path): bool { } - public function stat($path) + public function stat($path): array|false { } - public function getMetaData($path) + public function getMetaData($path): ?array { } - public function filetype($path) + public function filetype($path): string|false { } - public function filesize($path): false|int|float + public function filesize($path): int|float|false { } - public function isReadable($path) + public function isReadable($path): bool { } - public function isUpdatable($path) + public function isUpdatable($path): bool { } - public function file_exists($path) + public function file_exists($path): bool { } - public function filemtime($path) + public function filemtime($path): int|false { } - public function touch($path, $mtime = null) + public function touch($path, $mtime = null): bool { } - public function file_get_contents($path) + public function file_get_contents($path): string|false { } - public function file_put_contents($path, $data) + public function file_put_contents($path, $data): int|float|false { } - public function unlink($path) + public function unlink($path): bool { } @@ -117,7 +117,7 @@ public function rename($source, $target): bool { } - public function copy($source, $target) + public function copy($source, $target): bool { } @@ -129,35 +129,27 @@ public function hash($type, $path, $raw = false): string|false { } - public function free_space($path) + public function free_space($path): int|float|false { } - public function search($query) + public function search($query): array { } - public function getLocalFile($path) + public function getLocalFile($path): string|false { } /** * @param string $query * @param string $dir - * @return array */ - protected function searchInDir($query, $dir = '') + protected function searchInDir($query, $dir = ''): array { } - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - */ - public function hasUpdated($path, $time) + public function hasUpdated($path, $time): bool { } @@ -165,32 +157,21 @@ public function hasUpdated($path, $time) * Get the source path (on disk) of a given path * * @param string $path - * @return string * @throws ForbiddenException */ - public function getSourcePath($path) + public function getSourcePath($path): string { } - /** - * {@inheritdoc} - */ - public function isLocal() + public function isLocal(): bool { } - public function getETag($path) + public function getETag($path): string|false { } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @param bool $preserveMtime - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false): bool { } @@ -200,7 +181,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t * @param string $targetInternalPath * @return bool */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { } diff --git a/tests/stubs/oc_files_storage_storage.php b/tests/stubs/oc_files_storage_storage.php index a55f955de..0c4dde003 100644 --- a/tests/stubs/oc_files_storage_storage.php +++ b/tests/stubs/oc_files_storage_storage.php @@ -8,11 +8,11 @@ namespace OC\Files\Storage; -use OC\Files\Cache\Cache; -use OC\Files\Cache\Propagator; -use OC\Files\Cache\Scanner; -use OC\Files\Cache\Updater; -use OC\Files\Cache\Watcher; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IUpdater; +use OCP\Files\Cache\IWatcher; use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IStorage; @@ -23,57 +23,51 @@ */ interface Storage extends IStorage, ILockingStorage { /** - * @inheritDoc - * @return Cache + * @param string $path + * @param ?IStorage $storage */ - public function getCache($path = '', $storage = null) + public function getCache($path = '', $storage = null): ICache { } /** - * @inheritDoc - * @return Scanner + * @param string $path + * @param ?IStorage $storage */ - public function getScanner($path = '', $storage = null) + public function getScanner($path = '', $storage = null): IScanner { } /** - * @inheritDoc - * @return Watcher + * @param string $path + * @param ?IStorage $storage */ - public function getWatcher($path = '', $storage = null) + public function getWatcher($path = '', $storage = null): IWatcher { } /** - * @inheritDoc - * @return Propagator + * @param ?IStorage $storage */ - public function getPropagator($storage = null) + public function getPropagator($storage = null): IPropagator { } /** - * @inheritDoc - * @return Updater + * @param ?IStorage $storage */ - public function getUpdater($storage = null) + public function getUpdater($storage = null): IUpdater { } - /** - * @return \OC\Files\Cache\Storage - */ - public function getStorageCache() + public function getStorageCache(): \OC\Files\Cache\Storage { } /** * @param string $path - * @return array|null */ - public function getMetaData($path) + public function getMetaData($path): ?array { } @@ -81,7 +75,6 @@ public function getMetaData($path) * Get the contents of a directory with metadata * * @param string $directory - * @return \Traversable an iterator, containing file metadata * * The metadata array will contain the following fields * @@ -93,7 +86,7 @@ public function getMetaData($path) * - storage_mtime * - permissions */ - public function getDirectoryContent($directory): \Traversable + public function getDirectoryContent($directory): \Traversable|false { } } diff --git a/tests/stubs/oc_files_storage_temporary.php b/tests/stubs/oc_files_storage_temporary.php index 36213f450..8127a877c 100644 --- a/tests/stubs/oc_files_storage_temporary.php +++ b/tests/stubs/oc_files_storage_temporary.php @@ -15,7 +15,7 @@ public function __construct($arguments = []) { } - public function cleanUp() + public function cleanUp(): void { } @@ -23,7 +23,7 @@ public function __destruct() { } - public function getDataDir() + public function getDataDir(): array|string { } } diff --git a/tests/stubs/oc_files_storage_wrapper_jail.php b/tests/stubs/oc_files_storage_wrapper_jail.php index 937da97e3..79e093556 100644 --- a/tests/stubs/oc_files_storage_wrapper_jail.php +++ b/tests/stubs/oc_files_storage_wrapper_jail.php @@ -11,6 +11,9 @@ use OC\Files\Cache\Wrapper\JailPropagator; use OC\Files\Cache\Wrapper\JailWatcher; use OC\Files\Filesystem; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IWatcher; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; use OCP\Lock\ILockingProvider; @@ -36,321 +39,139 @@ public function __construct($arguments) { } - public function getUnjailedPath($path) + public function getUnjailedPath($path): string { } /** * This is separate from Wrapper::getWrapperStorage so we can get the jailed storage consistently even if the jail is inside another wrapper */ - public function getUnjailedStorage() + public function getUnjailedStorage(): IStorage { } - public function getJailedPath($path) + public function getJailedPath($path): ?string { } - public function getId() + public function getId(): string { } - /** - * see https://www.php.net/manual/en/function.mkdir.php - * - * @param string $path - * @return bool - */ - public function mkdir($path) + public function mkdir($path): bool { } - /** - * see https://www.php.net/manual/en/function.rmdir.php - * - * @param string $path - * @return bool - */ - public function rmdir($path) + public function rmdir($path): bool { } - /** - * see https://www.php.net/manual/en/function.opendir.php - * - * @param string $path - * @return resource|false - */ public function opendir($path) { } - /** - * see https://www.php.net/manual/en/function.is_dir.php - * - * @param string $path - * @return bool - */ - public function is_dir($path) + public function is_dir($path): bool { } - /** - * see https://www.php.net/manual/en/function.is_file.php - * - * @param string $path - * @return bool - */ - public function is_file($path) + public function is_file($path): bool { } - /** - * 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|bool - */ - public function stat($path) + public function stat($path): array|false { } - /** - * see https://www.php.net/manual/en/function.filetype.php - * - * @param string $path - * @return bool - */ - public function filetype($path) + public function filetype($path): string|false { } - /** - * see https://www.php.net/manual/en/function.filesize.php - * The result for filesize when called on a folder is required to be 0 - */ - public function filesize($path): false|int|float + public function filesize($path): int|float|false { } - /** - * check if a file can be created in $path - * - * @param string $path - * @return bool - */ - public function isCreatable($path) + public function isCreatable($path): bool { } - /** - * check if a file can be read - * - * @param string $path - * @return bool - */ - public function isReadable($path) + public function isReadable($path): bool { } - /** - * check if a file can be written to - * - * @param string $path - * @return bool - */ - public function isUpdatable($path) + public function isUpdatable($path): bool { } - /** - * check if a file can be deleted - * - * @param string $path - * @return bool - */ - public function isDeletable($path) + public function isDeletable($path): bool { } - /** - * check if a file can be shared - * - * @param string $path - * @return bool - */ - public function isSharable($path) + public function isSharable($path): bool { } - /** - * 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 - */ - public function getPermissions($path) + public function getPermissions($path): int { } - /** - * see https://www.php.net/manual/en/function.file_exists.php - * - * @param string $path - * @return bool - */ - public function file_exists($path) + public function file_exists($path): bool { } - /** - * see https://www.php.net/manual/en/function.filemtime.php - * - * @param string $path - * @return int|bool - */ - public function filemtime($path) + public function filemtime($path): int|false { } - /** - * see https://www.php.net/manual/en/function.file_get_contents.php - * - * @param string $path - * @return string|false - */ - public function file_get_contents($path) + public function file_get_contents($path): string|false { } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data) + public function file_put_contents($path, $data): int|float|false { } - /** - * see https://www.php.net/manual/en/function.unlink.php - * - * @param string $path - * @return bool - */ - public function unlink($path) + public function unlink($path): bool { } - /** - * see https://www.php.net/manual/en/function.rename.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function rename($source, $target) + public function rename($source, $target): bool { } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function copy($source, $target) + public function copy($source, $target): bool { } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - */ public function fopen($path, $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|bool - */ - public function getMimeType($path) + public function getMimeType($path): string|false { } - /** - * see https://www.php.net/manual/en/function.hash.php - * - * @param string $type - * @param string $path - * @param bool $raw - * @return string|bool - */ - public function hash($type, $path, $raw = false) + public function hash($type, $path, $raw = false): string|false { } - /** - * see https://www.php.net/manual/en/function.free_space.php - * - * @param string $path - * @return int|float|bool - */ - public function free_space($path) + public function free_space($path): int|float|false { } - /** - * 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 - */ - public function touch($path, $mtime = null) + public function touch($path, $mtime = null): bool { } - /** - * 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 - */ - public function getLocalFile($path) + public function getLocalFile($path): string|false { } - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - * - * 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($path, $time): bool { } - public function getCache($path = '', $storage = null) + public function getCache($path = '', $storage = null): ICache { } @@ -358,33 +179,27 @@ public function getOwner($path): string|false { } - public function getWatcher($path = '', $storage = null) + public function getWatcher($path = '', $storage = null): IWatcher { } - /** - * get the ETag for a file or folder - * - * @param string $path - * @return string|false - */ - public function getETag($path) + public function getETag($path): string|false { } - public function getMetaData($path) + public function getMetaData($path): ?array { } - public function acquireLock($path, $type, ILockingProvider $provider) + public function acquireLock($path, $type, ILockingProvider $provider): void { } - public function releaseLock($path, $type, ILockingProvider $provider) + public function releaseLock($path, $type, ILockingProvider $provider): void { } - public function changeLock($path, $type, ILockingProvider $provider) + public function changeLock($path, $type, ILockingProvider $provider): void { } @@ -392,33 +207,20 @@ public function changeLock($path, $type, ILockingProvider $provider) * Resolve the path for the source of the share * * @param string $path - * @return array */ - public function resolvePath($path) + public function resolvePath($path): array { } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { } - public function getPropagator($storage = null) + public function getPropagator($storage = null): IPropagator { } @@ -426,7 +228,7 @@ public function writeStream(string $path, $stream, ?int $size = null): int { } - public function getDirectoryContent($directory): \Traversable + public function getDirectoryContent($directory): \Traversable|false { } } diff --git a/tests/stubs/oc_files_storage_wrapper_permissionsmask.php b/tests/stubs/oc_files_storage_wrapper_permissionsmask.php index 665601323..59a780821 100644 --- a/tests/stubs/oc_files_storage_wrapper_permissionsmask.php +++ b/tests/stubs/oc_files_storage_wrapper_permissionsmask.php @@ -28,51 +28,51 @@ public function __construct($arguments) { } - public function isUpdatable($path) + public function isUpdatable($path): bool { } - public function isCreatable($path) + public function isCreatable($path): bool { } - public function isDeletable($path) + public function isDeletable($path): bool { } - public function isSharable($path) + public function isSharable($path): bool { } - public function getPermissions($path) + public function getPermissions($path): int { } - public function rename($source, $target) + public function rename($source, $target): bool { } - public function copy($source, $target) + public function copy($source, $target): bool { } - public function touch($path, $mtime = null) + public function touch($path, $mtime = null): bool { } - public function mkdir($path) + public function mkdir($path): bool { } - public function rmdir($path) + public function rmdir($path): bool { } - public function unlink($path) + public function unlink($path): bool { } - public function file_put_contents($path, $data) + public function file_put_contents($path, $data): int|float|false { } @@ -80,15 +80,15 @@ public function fopen($path, $mode) { } - public function getCache($path = '', $storage = null) + public function getCache($path = '', $storage = null): \OCP\Files\Cache\ICache { } - public function getMetaData($path) + public function getMetaData($path): ?array { } - public function getScanner($path = '', $storage = null) + public function getScanner($path = '', $storage = null): \OCP\Files\Cache\IScanner { } diff --git a/tests/stubs/oc_files_storage_wrapper_quota.php b/tests/stubs/oc_files_storage_wrapper_quota.php index 08fcfcffe..226cc5e20 100644 --- a/tests/stubs/oc_files_storage_wrapper_quota.php +++ b/tests/stubs/oc_files_storage_wrapper_quota.php @@ -27,9 +27,6 @@ public function __construct($parameters) { } - /** - * @return int|float quota value - */ public function getQuota(): int|float { } @@ -37,80 +34,40 @@ public function getQuota(): int|float /** * @param string $path * @param IStorage $storage - * @return int|float */ - protected function getSize($path, $storage = null) + protected function getSize($path, $storage = null): int|float { } - /** - * Get free space as limited by the quota - * - * @param string $path - * @return int|float|bool - */ - public function free_space($path) + public function free_space($path): int|float|false { } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data) + public function file_put_contents($path, $data): int|float|false { } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function copy($source, $target) + public function copy($source, $target): bool { } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - */ public function fopen($path, $mode) { } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { } - public function mkdir($path) + public function mkdir($path): bool { } - public function touch($path, $mtime = null) + public function touch($path, $mtime = null): bool { } } diff --git a/tests/stubs/oc_files_storage_wrapper_wrapper.php b/tests/stubs/oc_files_storage_wrapper_wrapper.php index 8b9fcb456..22ddd1830 100644 --- a/tests/stubs/oc_files_storage_wrapper_wrapper.php +++ b/tests/stubs/oc_files_storage_wrapper_wrapper.php @@ -8,7 +8,12 @@ namespace OC\Files\Storage\Wrapper; use OC\Files\Storage\FailedStorage; -use OCP\Files\InvalidPathException; +use OC\Files\Storage\Storage; +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IUpdater; +use OCP\Files\Cache\IWatcher; use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; @@ -35,323 +40,131 @@ public function __construct($parameters) { } - /** - * @return \OC\Files\Storage\Storage - */ - public function getWrapperStorage() + public function getWrapperStorage(): Storage { } - /** - * Get the identifier for the storage, - * the returned id should be the same for every storage object that is created with the same parameters - * and two storage objects with the same id should refer to two storages that display the same files. - * - * @return string - */ - public function getId() + public function getId(): string { } - /** - * see https://www.php.net/manual/en/function.mkdir.php - * - * @param string $path - * @return bool - */ - public function mkdir($path) + public function mkdir($path): bool { } - /** - * see https://www.php.net/manual/en/function.rmdir.php - * - * @param string $path - * @return bool - */ - public function rmdir($path) + public function rmdir($path): bool { } - /** - * see https://www.php.net/manual/en/function.opendir.php - * - * @param string $path - * @return resource|false - */ public function opendir($path) { } - /** - * see https://www.php.net/manual/en/function.is_dir.php - * - * @param string $path - * @return bool - */ - public function is_dir($path) + public function is_dir($path): bool { } - /** - * see https://www.php.net/manual/en/function.is_file.php - * - * @param string $path - * @return bool - */ - public function is_file($path) + public function is_file($path): bool { } - /** - * 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|bool - */ - public function stat($path) + public function stat($path): array|false { } - /** - * see https://www.php.net/manual/en/function.filetype.php - * - * @param string $path - * @return string|bool - */ - public function filetype($path) + public function filetype($path): string|false { } - /** - * see https://www.php.net/manual/en/function.filesize.php - * The result for filesize when called on a folder is required to be 0 - */ - public function filesize($path): false|int|float + public function filesize($path): int|float|false { } - /** - * check if a file can be created in $path - * - * @param string $path - * @return bool - */ - public function isCreatable($path) + public function isCreatable($path): bool { } - /** - * check if a file can be read - * - * @param string $path - * @return bool - */ - public function isReadable($path) + public function isReadable($path): bool { } - /** - * check if a file can be written to - * - * @param string $path - * @return bool - */ - public function isUpdatable($path) + public function isUpdatable($path): bool { } - /** - * check if a file can be deleted - * - * @param string $path - * @return bool - */ - public function isDeletable($path) + public function isDeletable($path): bool { } - /** - * check if a file can be shared - * - * @param string $path - * @return bool - */ - public function isSharable($path) + public function isSharable($path): bool { } - /** - * 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 - */ - public function getPermissions($path) + public function getPermissions($path): int { } - /** - * see https://www.php.net/manual/en/function.file_exists.php - * - * @param string $path - * @return bool - */ - public function file_exists($path) + public function file_exists($path): bool { } - /** - * see https://www.php.net/manual/en/function.filemtime.php - * - * @param string $path - * @return int|bool - */ - public function filemtime($path) + public function filemtime($path): int|false { } - /** - * see https://www.php.net/manual/en/function.file_get_contents.php - * - * @param string $path - * @return string|false - */ - public function file_get_contents($path) + public function file_get_contents($path): string|false { } - /** - * see https://www.php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param mixed $data - * @return int|float|false - */ - public function file_put_contents($path, $data) + public function file_put_contents($path, $data): int|float|false { } - /** - * see https://www.php.net/manual/en/function.unlink.php - * - * @param string $path - * @return bool - */ - public function unlink($path) + public function unlink($path): bool { } - /** - * see https://www.php.net/manual/en/function.rename.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function rename($source, $target) + public function rename($source, $target): bool { } - /** - * see https://www.php.net/manual/en/function.copy.php - * - * @param string $source - * @param string $target - * @return bool - */ - public function copy($source, $target) + public function copy($source, $target): bool { } - /** - * see https://www.php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|bool - */ public function fopen($path, $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|bool - */ - public function getMimeType($path) + public function getMimeType($path): string|false { } - /** - * see https://www.php.net/manual/en/function.hash.php - * - * @param string $type - * @param string $path - * @param bool $raw - * @return string|bool - */ - public function hash($type, $path, $raw = false) + public function hash($type, $path, $raw = false): string|false { } - /** - * see https://www.php.net/manual/en/function.free_space.php - * - * @param string $path - * @return int|float|bool - */ - public function free_space($path) + public function free_space($path): int|float|false { } - /** - * 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 - */ - public function touch($path, $mtime = null) + public function touch($path, $mtime = null): bool { } - /** - * 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 - */ - public function getLocalFile($path) + public function getLocalFile($path): string|false { } - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - * - * 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($path, $time): bool { } - public function getCache($path = '', $storage = null) + public function getCache($path = '', $storage = null): ICache { } - public function getScanner($path = '', $storage = null) + public function getScanner($path = '', $storage = null): IScanner { } @@ -359,57 +172,35 @@ public function getOwner($path): string|false { } - public function getWatcher($path = '', $storage = null) + public function getWatcher($path = '', $storage = null): IWatcher { } - public function getPropagator($storage = null) + public function getPropagator($storage = null): IPropagator { } - public function getUpdater($storage = null) + public function getUpdater($storage = null): IUpdater { } - public function getStorageCache() + public function getStorageCache(): \OC\Files\Cache\Storage { } - /** - * get the ETag for a file or folder - * - * @param string $path - * @return string|false - */ - public function getETag($path) + public function getETag($path): string|false { } - /** - * Returns true - * - * @return true - */ - public function test() + public function test(): bool { } - /** - * Returns the wrapped storage's value for isLocal() - * - * @return bool wrapped storage's isLocal() value - */ - public function isLocal() + public function isLocal(): bool { } - /** - * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class - * - * @param class-string $class - * @return bool - */ - public function instanceOfStorage($class) + public function instanceOfStorage($class): bool { } @@ -418,7 +209,7 @@ public function instanceOfStorage($class) * @psalm-param class-string $class * @psalm-return T|null */ - public function getInstanceOfStorage(string $class) + public function getInstanceOfStorage(string $class): ?IStorage { } @@ -433,86 +224,47 @@ public function __call($method, $args) { } - /** - * 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|bool - */ - public function getDirectDownload($path) + public function getDirectDownload($path): array|false { } - /** - * Get availability of the storage - * - * @return array [ available, last_checked ] - */ - public function getAvailability() + public function getAvailability(): array { } - /** - * Set availability of the storage - * - * @param bool $isAvailable - */ - public function setAvailability($isAvailable) + public function setAvailability($isAvailable): void { } - /** - * @param string $path the path of the target folder - * @param string $fileName the name of the file itself - * @return void - * @throws InvalidPathException - */ - public function verifyPath($path, $fileName) + public function verifyPath($path, $fileName): void { } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { } - /** - * @param IStorage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - */ - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath): bool { } - public function getMetaData($path) + public function getMetaData($path): ?array { } - public function acquireLock($path, $type, ILockingProvider $provider) + public function acquireLock($path, $type, ILockingProvider $provider): void { } - public function releaseLock($path, $type, ILockingProvider $provider) + public function releaseLock($path, $type, ILockingProvider $provider): void { } - public function changeLock($path, $type, ILockingProvider $provider) + public function changeLock($path, $type, ILockingProvider $provider): void { } - /** - * @return bool - */ - public function needsPartFile() + public function needsPartFile(): bool { } @@ -520,11 +272,11 @@ public function writeStream(string $path, $stream, ?int $size = null): int { } - public function getDirectoryContent($directory): \Traversable + public function getDirectoryContent($directory): \Traversable|false { } - public function isWrapperOf(IStorage $storage) + public function isWrapperOf(IStorage $storage): bool { } diff --git a/tests/stubs/oc_server.php b/tests/stubs/oc_server.php index f3f822823..4b5461a9b 100644 --- a/tests/stubs/oc_server.php +++ b/tests/stubs/oc_server.php @@ -216,6 +216,7 @@ use OCP\Security\ITrustedDomainHelper; use OCP\Security\RateLimiting\ILimiter; use OCP\Security\VerificationToken\IVerificationToken; +use OCP\ServerVersion; use OCP\Settings\IDeclarativeManager; use OCP\SetupCheck\ISetupCheckManager; use OCP\Share\IProviderFactory; diff --git a/tests/stubs/ocp_files_storage_iconstructablestorage.php b/tests/stubs/ocp_files_storage_iconstructablestorage.php new file mode 100644 index 000000000..beee0ae1e --- /dev/null +++ b/tests/stubs/ocp_files_storage_iconstructablestorage.php @@ -0,0 +1,28 @@ + Date: Thu, 26 Sep 2024 18:17:06 +0200 Subject: [PATCH 2/2] fix(ACLStorageWrapper): Fix return types Signed-off-by: provokateurin --- lib/ACL/ACLStorageWrapper.php | 24 ++++++++++++++---------- tests/ACL/ACLScannerTest.php | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/ACL/ACLStorageWrapper.php b/lib/ACL/ACLStorageWrapper.php index 5d14a8c1c..6ce7c8714 100644 --- a/lib/ACL/ACLStorageWrapper.php +++ b/lib/ACL/ACLStorageWrapper.php @@ -9,10 +9,10 @@ namespace OCA\GroupFolders\ACL; use Icewind\Streams\IteratorDirectory; -use OC\Files\Cache\Scanner; use OC\Files\Storage\Wrapper\Wrapper; use OCP\Constants; use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IScanner; use OCP\Files\Storage\IStorage; class ACLStorageWrapper extends Wrapper { @@ -204,7 +204,7 @@ public function getMetaData($path): ?array { * @param string $path * @param ?IStorage $storage */ - public function getScanner($path = '', $storage = null): Scanner { + public function getScanner($path = '', $storage = null): IScanner { if (!$storage) { $storage = $this->storage; } @@ -222,7 +222,7 @@ public function is_file($path): bool { parent::is_file($path); } - public function stat($path): array|bool { + public function stat($path): array|false { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -230,7 +230,7 @@ public function stat($path): array|bool { return parent::stat($path); } - public function filetype($path): string|bool { + public function filetype($path): string|false { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -251,7 +251,7 @@ public function file_exists($path): bool { parent::file_exists($path); } - public function filemtime($path): int|bool { + public function filemtime($path): int|false { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -267,7 +267,7 @@ public function file_get_contents($path): string|false { return parent::file_get_contents($path); } - public function getMimeType($path): string|bool { + public function getMimeType($path): string|false { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -275,7 +275,7 @@ public function getMimeType($path): string|bool { return parent::getMimeType($path); } - public function hash($type, $path, $raw = false): string|bool { + public function hash($type, $path, $raw = false): string|false { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -291,7 +291,7 @@ public function getETag($path): string|false { return parent::getETag($path); } - public function getDirectDownload($path): array|bool { + public function getDirectDownload($path): array|false { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -299,8 +299,12 @@ public function getDirectDownload($path): array|bool { return parent::getDirectDownload($path); } - public function getDirectoryContent($directory): \Traversable { - foreach ($this->getWrapperStorage()->getDirectoryContent($directory) as $data) { + public function getDirectoryContent($directory): \Traversable|false { + $content = $this->getWrapperStorage()->getDirectoryContent($directory); + if ($content === false) { + return false; + } + foreach ($content as $data) { $data['scan_permissions'] ??= $data['permissions']; $data['permissions'] &= $this->getACLPermissionsForPath(rtrim($directory, '/') . '/' . $data['name']); diff --git a/tests/ACL/ACLScannerTest.php b/tests/ACL/ACLScannerTest.php index 622f0632d..f6ef0fd40 100644 --- a/tests/ACL/ACLScannerTest.php +++ b/tests/ACL/ACLScannerTest.php @@ -7,6 +7,7 @@ namespace OCA\groupfolders\tests\ACL; +use OC\Files\Cache\Cache; use OC\Files\Storage\Temporary; use OCA\GroupFolders\ACL\ACLManager; use OCA\GroupFolders\ACL\ACLStorageWrapper; @@ -33,6 +34,7 @@ public function testScanAclStorage(): void { $baseStorage->mkdir('foo'); $baseStorage->mkdir('foo/bar'); $baseStorage->mkdir('foo/bar/asd'); + /** @var Cache $cache */ $cache = $baseStorage->getCache(); $baseStorage->getScanner()->scan('');