From 534cb3e8da5c6ad44c0452b93f7177b2ee51e8ab Mon Sep 17 00:00:00 2001 From: provokateurin Date: Fri, 20 Sep 2024 00:02:55 +0200 Subject: [PATCH] fix(psalm): Enable psalm level 3 Signed-off-by: provokateurin --- lib/ACL/ACLManager.php | 5 +++++ lib/ACL/ACLStorageWrapper.php | 4 ++++ lib/ACL/UserMapping/UserMappingManager.php | 1 + lib/DAV/ACLPlugin.php | 4 ++-- lib/Folder/FolderManager.php | 10 +++++----- lib/Mount/GroupMountPoint.php | 7 +++---- lib/Mount/MountProvider.php | 3 +++ psalm.xml | 2 +- 8 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/ACL/ACLManager.php b/lib/ACL/ACLManager.php index b6a5fa3b0..4e6891568 100644 --- a/lib/ACL/ACLManager.php +++ b/lib/ACL/ACLManager.php @@ -14,6 +14,7 @@ use OCP\Files\IRootFolder; use OCP\IUser; use Psr\Log\LoggerInterface; +use RuntimeException; class ACLManager { private CappedMemoryCache $ruleCache; @@ -88,6 +89,9 @@ private function getRelevantPaths(string $path): array { $groupFolderId = (int)$groupFolderId; /* Remove the date part */ $separatorPos = strrpos($rootTrashedItemName, '.d'); + if ($separatorPos === false) { + throw new RuntimeException('Invalid trash item name ' . $rootTrashedItemName); + } $rootTrashedItemDate = (int)substr($rootTrashedItemName, $separatorPos + 2); $rootTrashedItemName = substr($rootTrashedItemName, 0, $separatorPos); } @@ -97,6 +101,7 @@ private function getRelevantPaths(string $path): array { $path = dirname($path); if ($fromTrashbin && ($path === '__groupfolders/trash')) { /* We are in trash and hit the root folder, continue looking for ACLs on parent folders in original location */ + /** @psalm-suppress PossiblyUndefinedVariable Variables are defined above */ $trashItemRow = $this->trashManager->getTrashItemByFileName($groupFolderId, $rootTrashedItemName, $rootTrashedItemDate); $fromTrashbin = false; if ($trashItemRow) { diff --git a/lib/ACL/ACLStorageWrapper.php b/lib/ACL/ACLStorageWrapper.php index 66a0d45e5..5d14a8c1c 100644 --- a/lib/ACL/ACLStorageWrapper.php +++ b/lib/ACL/ACLStorageWrapper.php @@ -101,6 +101,10 @@ public function opendir($path) { } $handle = parent::opendir($path); + if ($handle === false) { + return false; + } + $items = []; while (($file = readdir($handle)) !== false) { if ($file !== '.' && $file !== '..') { diff --git a/lib/ACL/UserMapping/UserMappingManager.php b/lib/ACL/UserMapping/UserMappingManager.php index ef74e4732..33a607666 100644 --- a/lib/ACL/UserMapping/UserMappingManager.php +++ b/lib/ACL/UserMapping/UserMappingManager.php @@ -32,6 +32,7 @@ public function mappingFromId(string $type, string $id): ?IUserMapping { $mappingObject = ($type === 'group' ? $this->groupManager : $this->userManager)->get($id); if ($mappingObject) { $displayName = $mappingObject->getDisplayName(); + /** @var 'user'|'group' $type */ return new UserMapping($type, $id, $displayName); } else { return null; diff --git a/lib/DAV/ACLPlugin.php b/lib/DAV/ACLPlugin.php index c5afd9051..caa99880a 100644 --- a/lib/DAV/ACLPlugin.php +++ b/lib/DAV/ACLPlugin.php @@ -11,7 +11,7 @@ use OCA\DAV\Connector\Sabre\Node; use OCA\GroupFolders\ACL\Rule; use OCA\GroupFolders\ACL\RuleManager; -use OCA\GroupFolders\ACL\UserMapping\UserMapping; +use OCA\GroupFolders\ACL\UserMapping\IUserMapping; use OCA\GroupFolders\Folder\FolderManager; use OCA\GroupFolders\Mount\GroupMountPoint; use OCP\Constants; @@ -145,7 +145,7 @@ public function propFind(PropFind $propFind, INode $node): void { } } - return array_map(fn (UserMapping $mapping, int $permissions, int $mask): Rule => new Rule( + return array_map(fn (IUserMapping $mapping, int $permissions, int $mask): Rule => new Rule( $mapping, $fileInfo->getId(), $mask, diff --git a/lib/Folder/FolderManager.php b/lib/Folder/FolderManager.php index 8eb0f9d98..8dcd615de 100644 --- a/lib/Folder/FolderManager.php +++ b/lib/Folder/FolderManager.php @@ -95,7 +95,7 @@ private function joinQueryWithFileCache(IQueryBuilder $query, int $rootStorageId } /** - * @return array, id: int, manage: array, mount_point: mixed, quota: int, size: int}> + * @return array, id: int, manage: array, mount_point: mixed, quota: int, size: int}> * @throws Exception */ public function getAllFoldersWithSize(int $rootStorageId): array { @@ -130,7 +130,7 @@ public function getAllFoldersWithSize(int $rootStorageId): array { } /** - * @return array, id: int, manage: array, mount_point: mixed, quota: int, size: int}> + * @return array, id: int, manage: array, mount_point: mixed, quota: int, size: int}> * @throws Exception */ public function getAllFoldersForUserWithSize(int $rootStorageId, IUser $user): array { @@ -212,7 +212,7 @@ private function getFolderMappings(int $id): array { } /** - * @return array{type?: 'user'|'group', id?: string, displayname?: string}[] + * @return array{type: 'user'|'group', id: string, displayname: string}[] */ private function getManageAcl(array $mappings): array { return array_filter(array_map(function (array $entry): ?array { @@ -231,7 +231,7 @@ private function getManageAcl(array $mappings): array { $group = Server::get(IGroupManager::class)->get($entry['mapping_id']); if ($group === null) { - return []; + return null; } return [ @@ -239,7 +239,7 @@ private function getManageAcl(array $mappings): array { 'id' => $group->getGID(), 'displayname' => $group->getDisplayName() ]; - }, $mappings), fn (?array $element): bool => $element !== null); + }, $mappings)); } /** diff --git a/lib/Mount/GroupMountPoint.php b/lib/Mount/GroupMountPoint.php index 53c2e5c54..fa72e71f3 100644 --- a/lib/Mount/GroupMountPoint.php +++ b/lib/Mount/GroupMountPoint.php @@ -7,23 +7,22 @@ namespace OCA\GroupFolders\Mount; use OC\Files\Mount\MountPoint; +use OC\Files\Storage\Storage; use OCP\Files\Mount\ISystemMountPoint; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorageFactory; class GroupMountPoint extends MountPoint implements ISystemMountPoint { - /** - * @param IStorage $storage - */ public function __construct( private int $folderId, - $storage, + IStorage $storage, string $mountpoint, ?array $arguments = null, ?IStorageFactory $loader = null, ?array $mountOptions = null, ?int $mountId = null, ) { + /** @var Storage $storage */ parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, MountProvider::class); } diff --git a/lib/Mount/MountProvider.php b/lib/Mount/MountProvider.php index cd3bd4d58..5d966caa9 100644 --- a/lib/Mount/MountProvider.php +++ b/lib/Mount/MountProvider.php @@ -154,6 +154,9 @@ public function getMount( } $cacheEntry = $this->getRootFolder()->getStorage()->getCache()->get($folder->getId()); + if ($cacheEntry === false) { + return null; + } } $storage = $this->getRootFolder()->getStorage(); diff --git a/psalm.xml b/psalm.xml index 8915fab3b..05326da78 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,7 +4,7 @@ - SPDX-License-Identifier: AGPL-3.0-or-later -->