diff --git a/lib/private/Share20/ShareHelper.php b/lib/private/Share20/ShareHelper.php index d03f89443f5cd..98c413b55b881 100644 --- a/lib/private/Share20/ShareHelper.php +++ b/lib/private/Share20/ShareHelper.php @@ -1,5 +1,7 @@ [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]] - */ - public function getPathsForAccessList(Node $node) { + #[Override] + public function getPathsForAccessList(Node $node): array { $result = [ 'users' => [], 'remotes' => [], ]; $accessList = $this->shareManager->getAccessList($node, true, true); - if (!empty($accessList['users'])) { + if (isset($accessList['users']) && $accessList['users'] !== []) { $result['users'] = $this->getPathsForUsers($node, $accessList['users']); } - if (!empty($accessList['remote'])) { + + if (isset($accessList['remote']) && $accessList['remote'] !== []) { $result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']); } @@ -60,20 +61,20 @@ public function getPathsForAccessList(Node $node) { * 'test3' => '/cat', * ], * - * @param Node $node - * @param array[] $users - * @return array + * @param non-empty-array $users + * @return array */ - protected function getPathsForUsers(Node $node, array $users) { - /** @var array[] $byId */ + protected function getPathsForUsers(Node $node, array $users): array { + /** @var array> $byId */ $byId = []; - /** @var array[] $results */ + /** @var array $results */ $results = []; foreach ($users as $uid => $info) { if (!isset($byId[$info['node_id']])) { $byId[$info['node_id']] = []; } + $byId[$info['node_id']][$uid] = $info['node_path']; } @@ -82,15 +83,14 @@ protected function getPathsForUsers(Node $node, array $users) { foreach ($byId[$node->getId()] as $uid => $path) { $results[$uid] = $path; } + unset($byId[$node->getId()]); } - } catch (NotFoundException $e) { - return $results; - } catch (InvalidPathException $e) { + } catch (NotFoundException|InvalidPathException) { return $results; } - if (empty($byId)) { + if ($byId === []) { return $results; } @@ -98,22 +98,18 @@ protected function getPathsForUsers(Node $node, array $users) { $appendix = '/' . $node->getName(); while (!empty($byId)) { try { - /** @var Node $item */ $item = $item->getParent(); - if (!empty($byId[$item->getId()])) { + if ($byId[$item->getId()] !== []) { foreach ($byId[$item->getId()] as $uid => $path) { $results[$uid] = $path . $appendix; } + unset($byId[$item->getId()]); } $appendix = '/' . $item->getName() . $appendix; - } catch (NotFoundException $e) { - return $results; - } catch (InvalidPathException $e) { - return $results; - } catch (NotPermittedException $e) { + } catch (NotFoundException|InvalidPathException|NotPermittedException) { return $results; } } @@ -141,27 +137,27 @@ protected function getPathsForUsers(Node $node, array $users) { * 'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'], * ], * - * @param Node $node - * @param array[] $remotes - * @return array + * @param non-empty-array $remotes + * @return array */ - protected function getPathsForRemotes(Node $node, array $remotes) { - /** @var array[] $byId */ + protected function getPathsForRemotes(Node $node, array $remotes): array { + /** @var array> $byId */ $byId = []; - /** @var array[] $results */ + /** @var array $results */ $results = []; foreach ($remotes as $cloudId => $info) { if (!isset($byId[$info['node_id']])) { $byId[$info['node_id']] = []; } + $byId[$info['node_id']][$cloudId] = $info['token']; } $item = $node; while (!empty($byId)) { try { - if (!empty($byId[$item->getId()])) { + if ($byId[$item->getId()] !== []) { $path = $this->getMountedPath($item); foreach ($byId[$item->getId()] as $uid => $token) { $results[$uid] = [ @@ -169,16 +165,12 @@ protected function getPathsForRemotes(Node $node, array $remotes) { 'token' => $token, ]; } + unset($byId[$item->getId()]); } - /** @var Node $item */ $item = $item->getParent(); - } catch (NotFoundException $e) { - return $results; - } catch (InvalidPathException $e) { - return $results; - } catch (NotPermittedException $e) { + } catch (NotFoundException|InvalidPathException|NotPermittedException) { return $results; } } @@ -186,11 +178,7 @@ protected function getPathsForRemotes(Node $node, array $remotes) { return $results; } - /** - * @param Node $node - * @return string - */ - protected function getMountedPath(Node $node) { + protected function getMountedPath(Node $node): string { $path = $node->getPath(); $sections = explode('/', $path, 4); return '/' . $sections[3]; diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php index 9abaff980f27f..6a53646f559ce 100644 --- a/lib/public/Share/IManager.php +++ b/lib/public/Share/IManager.php @@ -258,9 +258,9 @@ public function userDeletedFromGroup(string $uid, string $gid): void; * @return ($currentAccess is true * ? array{ * users?: array, - * remote?: array, + * remote?: array, * public?: bool, - * mail?: array + * mail?: array * } * : array{users?: list, remote?: bool, public?: bool, mail?: list}) * @since 12.0.0 diff --git a/lib/public/Share/IShareHelper.php b/lib/public/Share/IShareHelper.php index 152fc99a446a6..9c91aa32c8c63 100644 --- a/lib/public/Share/IShareHelper.php +++ b/lib/public/Share/IShareHelper.php @@ -1,23 +1,26 @@ [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]] + * @return array{users: array, remotes: array} [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]] * @since 12 */ - public function getPathsForAccessList(Node $node); + public function getPathsForAccessList(Node $node): array; } diff --git a/psalm-strict.xml b/psalm-strict.xml index 85bfce79a3119..23cd2081c0b70 100644 --- a/psalm-strict.xml +++ b/psalm-strict.xml @@ -28,6 +28,8 @@ + +