From 695165260f26b2f5b5584e619e54741db1a2d9cc Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 10 Jan 2022 11:36:51 +0100 Subject: Add helper method in Wrapper Signed-off-by: Carl Schwan --- lib/private/Files/Storage/Wrapper/Wrapper.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 5faffece67e..b44db7c13ce 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -486,7 +486,7 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea /** * 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 + * @param class-string $class * @return bool */ public function instanceOfStorage($class) { @@ -497,6 +497,25 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea return is_a($this, $class) or $this->getWrapperStorage()->instanceOfStorage($class); } + /** + * @template T of IStorage + * @param class-string $class + * @return ?T + */ + public function getInstanceOfStorage(string $class): ?IStorage { + $storage = $this; + while ($storage->instanceOfStorage(Wrapper::class)) { + if ($storage instanceof $class) { + break; + } + $storage = $storage->getWrapperStorage(); + } + if (!is_a($storage, $class)) { + return null; + } + return $storage; + } + /** * Pass any methods custom to specific storage implementations to the wrapped storage * -- cgit v1.2.3 From cbf9064b8ecde6f497146f6711fff83307a0730f Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 13 Jan 2022 12:30:27 +0100 Subject: Fix psalm issues Signed-off-by: Carl Schwan --- apps/workflowengine/lib/Check/FileSystemTags.php | 5 ++++- lib/private/Files/Storage/Wrapper/Wrapper.php | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/apps/workflowengine/lib/Check/FileSystemTags.php b/apps/workflowengine/lib/Check/FileSystemTags.php index d3f02729f2f..008f47eca78 100644 --- a/apps/workflowengine/lib/Check/FileSystemTags.php +++ b/apps/workflowengine/lib/Check/FileSystemTags.php @@ -144,7 +144,10 @@ class FileSystemTags implements ICheck, IFileCheck { if ($groupFolderStorage === null) { throw new \LogicException('Should not happen: Storage is instance of GroupFolderStorage but no group folder storage found while unwrapping.'); } - /** @psalm-suppress UndefinedMethod */ + /** + * @psalm-suppress UndefinedDocblockClass + * @psalm-suppress UndefinedInterfaceMethod + */ $cacheId = $cache->getNumericStorageId() . '/' . $groupFolderStorage->getFolderId(); } else { $cacheId = $cache->getNumericStorageId(); diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index b44db7c13ce..6bc66bf9c89 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -498,19 +498,19 @@ class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage, IWriteStrea } /** - * @template T of IStorage - * @param class-string $class - * @return ?T + * @psalm-template T of IStorage + * @psalm-param class-string $class + * @psalm-return T|null */ - public function getInstanceOfStorage(string $class): ?IStorage { + public function getInstanceOfStorage(string $class) { $storage = $this; - while ($storage->instanceOfStorage(Wrapper::class)) { + while ($storage instanceof Wrapper) { if ($storage instanceof $class) { break; } $storage = $storage->getWrapperStorage(); } - if (!is_a($storage, $class)) { + if (!($storage instanceof $class)) { return null; } return $storage; -- cgit v1.2.3