diff --git a/build/rector-strict.php b/build/rector-strict.php index 6df2c93be55a1..c1d47db0775ef 100644 --- a/build/rector-strict.php +++ b/build/rector-strict.php @@ -19,6 +19,7 @@ $nextcloudDir . '/apps/settings/lib/Service/AuthorizedGroupService.php', $nextcloudDir . '/lib/private/Files/Storage/Storage.php', $nextcloudDir . '/lib/private/Files/Storage/Wrapper/Wrapper.php', + $nextcloudDir . '/lib/private/Files/Storage/StorageFactory.php', $nextcloudDir . '/build/psalm/ITypedQueryBuilderTest.php', $nextcloudDir . '/lib/private/DB/QueryBuilder/TypedQueryBuilder.php', $nextcloudDir . '/lib/public/DB/QueryBuilder/ITypedQueryBuilder.php', diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index 3538a1386c577..78857cc67fe59 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -14,6 +14,7 @@ use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorageFactory; use OCP\Server; +use Override; use Psr\Log\LoggerInterface; class MountPoint implements IMountPoint { @@ -212,13 +213,11 @@ private function formatPath($path) { return $path; } - /** - * @param callable $wrapper - */ - public function wrapStorage($wrapper) { + #[Override] + public function wrapStorage($wrapper): void { $storage = $this->getStorage(); // storage can be null if it couldn't be initialized - if ($storage != null) { + if ($storage !== null) { $this->storage = $wrapper($this->mountPoint, $storage, $this); } } diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index 8354f382aa3be..294da7ef5200e 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -389,6 +389,7 @@ public function getFirstNodeByIdInPath(int $id, string $path): ?INode { } } } + $node = current($this->getByIdInPath($id, $path)); if (!$node) { return null; diff --git a/lib/private/Files/Storage/StorageFactory.php b/lib/private/Files/Storage/StorageFactory.php index 24efd3ecc1c45..3d7e4a1aba3ec 100644 --- a/lib/private/Files/Storage/StorageFactory.php +++ b/lib/private/Files/Storage/StorageFactory.php @@ -1,5 +1,7 @@ ['priority'=>$priority, 'wrapper'=>$callable] $storageWrappers - */ - private $storageWrappers = []; + /** @var array */ + private array $storageWrappers = []; + #[Override] public function addStorageWrapper(string $wrapperName, callable $callback, int $priority = 50, array $existingMounts = []): bool { if (isset($this->storageWrappers[$wrapperName])) { return false; @@ -44,31 +46,30 @@ public function removeStorageWrapper(string $wrapperName): void { unset($this->storageWrappers[$wrapperName]); } - /** - * Create an instance of a storage and apply the registered storage wrappers - */ + #[Override] public function getInstance(IMountPoint $mountPoint, string $class, array $arguments): IStorage { if (!is_a($class, IConstructableStorage::class, true)) { 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)); } public function wrap(IMountPoint $mountPoint, IStorage $storage): IStorage { - $wrappers = array_values($this->storageWrappers); - usort($wrappers, function ($a, $b) { - return $b['priority'] - $a['priority']; - }); - /** @var callable[] $wrappers */ - $wrappers = array_map(function ($wrapper) { - return $wrapper['wrapper']; - }, $wrappers); + $wrappers = $this->storageWrappers; + usort($wrappers, static fn (array $a, array $b): int + /** @var array{priority: int} $a + * @var array{priority: int} $b */ + => $b['priority'] - $a['priority']); + + $wrappers = array_map(static fn (array $wrapper): callable => $wrapper['wrapper'], $wrappers); foreach ($wrappers as $wrapper) { $storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint); - if (!($storage instanceof IStorage)) { + if (!$storage instanceof IStorage) { throw new \Exception('Invalid result from storage wrapper'); } } + return $storage; } } diff --git a/lib/private/Preview/PreviewMigrationService.php b/lib/private/Preview/PreviewMigrationService.php index 7c7581c631884..df1b22739c476 100644 --- a/lib/private/Preview/PreviewMigrationService.php +++ b/lib/private/Preview/PreviewMigrationService.php @@ -67,7 +67,7 @@ public function migrateFileId(int $fileId, bool $flatPath): array { /** @var SimpleFile $previewFile */ $preview = Preview::fromPath($path, $this->mimeTypeDetector); if ($preview === false) { - $this->logger->error('Unable to import old preview at path.'); + $this->logger->error('Unable to import old preview at path: ' . $path); continue; } $preview->generateId(); diff --git a/lib/public/Files/Mount/IMountPoint.php b/lib/public/Files/Mount/IMountPoint.php index 8989a885fda49..9aae8740df09c 100644 --- a/lib/public/Files/Mount/IMountPoint.php +++ b/lib/public/Files/Mount/IMountPoint.php @@ -7,8 +7,11 @@ */ namespace OCP\Files\Mount; +use OCP\Files\Storage\IStorage; + /** * A storage mounted to folder on the filesystem + * * @since 8.0.0 */ interface IMountPoint { @@ -64,7 +67,7 @@ public function getInternalPath($path); /** * Apply a storage wrapper to the mounted storage * - * @param callable $wrapper + * @param callable(string, IStorage, IMountPoint):IStorage $wrapper * @since 8.0.0 */ public function wrapStorage($wrapper); diff --git a/lib/public/Files/Storage/IStorageFactory.php b/lib/public/Files/Storage/IStorageFactory.php index 24f87d2e77544..a060049aa2307 100644 --- a/lib/public/Files/Storage/IStorageFactory.php +++ b/lib/public/Files/Storage/IStorageFactory.php @@ -7,27 +7,34 @@ */ namespace OCP\Files\Storage; +use OCP\AppFramework\Attribute\Consumable; use OCP\Files\Mount\IMountPoint; /** - * Creates storage instances and manages and applies storage wrappers + * Creates storage instances and manages and applies storage wrappers. + * * @since 8.0.0 */ +#[Consumable(since: '8.0.0')] interface IStorageFactory { /** - * allow modifier storage behaviour by adding wrappers around storages + * Allow modifier storage behaviour by adding wrappers around storages. * - * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage + * @param non-empty-string $wrapperName + * @param callable(string, IStorage, IMountPoint):IStorage $callback Callback should be a function of type (string $mountPoint, Storage $storage, IMountPoint) => Storage + * @param list $existingMounts * * @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(string $wrapperName, callable $callback); + public function addStorageWrapper(string $wrapperName, callable $callback, int $priority = 50, array $existingMounts = []): bool; /** - * @return IStorage + * Create an instance of a storage and apply the registered storage wrappers. + * + * @param class-string $class * @since 8.0.0 */ - public function getInstance(IMountPoint $mountPoint, string $class, array $arguments); + public function getInstance(IMountPoint $mountPoint, string $class, array $arguments): IStorage; } diff --git a/psalm-strict.xml b/psalm-strict.xml index 23cd2081c0b70..2ba2debea2bc8 100644 --- a/psalm-strict.xml +++ b/psalm-strict.xml @@ -25,6 +25,8 @@ + +