From a21dac1dc158201b04098db081315383fda50b8f Mon Sep 17 00:00:00 2001 From: provokateurin Date: Tue, 17 Sep 2024 16:50:21 +0200 Subject: [PATCH] fix: Fix all property, param and return types Signed-off-by: provokateurin --- lib/ACL/ACLCacheWrapper.php | 33 ++++---- lib/ACL/ACLManager.php | 20 ++--- lib/ACL/ACLManagerFactory.php | 5 +- lib/ACL/ACLStorageWrapper.php | 81 ++++++++++--------- lib/ACL/Rule.php | 49 ++++------- lib/ACL/RuleManager.php | 48 ++++------- lib/ACL/UserMapping/IUserMapping.php | 2 +- lib/ACL/UserMapping/IUserMappingManager.php | 6 -- lib/ACL/UserMapping/UserMapping.php | 15 ++-- lib/ACL/UserMapping/UserMappingManager.php | 12 ++- lib/AppInfo/Application.php | 16 ++-- lib/AppInfo/Capabilities.php | 13 ++- lib/AuthorizedAdminSettingMiddleware.php | 29 ++----- lib/BackgroundJob/ExpireGroupPlaceholder.php | 2 +- lib/BackgroundJob/ExpireGroupTrash.php | 16 +--- lib/BackgroundJob/ExpireGroupVersions.php | 7 +- lib/Command/ACL.php | 27 +++---- lib/Command/Create.php | 11 ++- lib/Command/Delete.php | 4 +- lib/Command/ExpireGroup/ExpireGroupTrash.php | 9 +-- .../ExpireGroup/ExpireGroupVersions.php | 7 +- .../ExpireGroup/ExpireGroupVersionsTrash.php | 9 +-- .../ExpireGroupVersionsPlaceholder.php | 8 +- lib/Command/FolderCommand.php | 12 ++- lib/Command/Group.php | 13 +-- lib/Command/ListCommand.php | 27 +++---- lib/Command/Quota.php | 4 +- lib/Command/Scan.php | 13 ++- lib/Command/Trashbin/Cleanup.php | 7 +- lib/Controller/FolderController.php | 40 +++------ lib/DAV/ACLPlugin.php | 30 +++---- lib/DAV/GroupFolderNode.php | 9 ++- lib/DAV/GroupFoldersHome.php | 23 ++---- lib/DAV/RootCollection.php | 2 - lib/Folder/FolderManager.php | 52 +++--------- .../Version1000000Date20210216085047.php | 9 --- .../Version102020Date20180806161449.php | 9 +-- .../Version103000Date20180806161724.php | 23 ++---- .../Version104000Date20180918132853.php | 5 +- .../Version16000Date20230821085801.php | 9 --- .../Version19000Date20240903062631.php | 9 --- .../Version201000Date20190111132839.php | 5 +- .../Version201000Date20190212150323.php | 5 +- .../Version300000Date20240905185515.php | 4 - .../Version401001Date20190715092137.php | 5 +- .../Version501000Date20190927102434.php | 8 +- .../Version501000Date20191218182434.php | 8 +- .../Version802000Date20201119112624.php | 2 +- lib/Migration/WrongDefaultQuotaRepairStep.php | 3 +- lib/Mount/CacheRootPermissionsMask.php | 11 +-- lib/Mount/GroupFolderEncryptionJail.php | 9 ++- lib/Mount/GroupFolderStorage.php | 21 ++++- lib/Mount/GroupMountPoint.php | 21 +++-- lib/Mount/MountProvider.php | 72 ++++------------- lib/Mount/RootEntryCache.php | 18 ++--- lib/Mount/RootPermissionsMask.php | 26 +++--- lib/Service/ApplicationService.php | 7 +- lib/Service/DelegationService.php | 25 +----- lib/Service/FoldersFilter.php | 14 ++-- lib/Settings/Admin.php | 9 +-- lib/Settings/Section.php | 31 +------ lib/Trash/GroupTrashItem.php | 14 ++-- lib/Trash/TrashBackend.php | 17 ++-- lib/Trash/TrashManager.php | 2 - lib/Versions/ExpireManager.php | 17 ++-- lib/Versions/GroupVersionsExpireManager.php | 21 ++--- lib/Versions/GroupVersionsMapper.php | 3 - lib/Versions/VersionsBackend.php | 11 +-- psalm.xml | 8 ++ 69 files changed, 400 insertions(+), 722 deletions(-) diff --git a/lib/ACL/ACLCacheWrapper.php b/lib/ACL/ACLCacheWrapper.php index 67fd4e67a..1c32a05a9 100644 --- a/lib/ACL/ACLCacheWrapper.php +++ b/lib/ACL/ACLCacheWrapper.php @@ -15,10 +15,15 @@ use OCP\Files\Search\ISearchQuery; class ACLCacheWrapper extends CacheWrapper { - private ACLManager $aclManager; - private bool $inShare; + public function __construct( + ICache $cache, + private ACLManager $aclManager, + private bool $inShare, + ) { + parent::__construct($cache); + } - private function getACLPermissionsForPath(string $path, array $rules = []) { + private function getACLPermissionsForPath(string $path, array $rules = []): int { if ($rules) { $permissions = $this->aclManager->getPermissionsForPathFromRules($path, $rules); } else { @@ -37,13 +42,7 @@ private function getACLPermissionsForPath(string $path, array $rules = []) { return $canRead ? $permissions : 0; } - public function __construct(ICache $cache, ACLManager $aclManager, bool $inShare) { - parent::__construct($cache); - $this->aclManager = $aclManager; - $this->inShare = $inShare; - } - - protected function formatCacheEntry($entry, array $rules = []) { + protected function formatCacheEntry($entry, array $rules = []): ICacheEntry|false { if (isset($entry['permissions'])) { $entry['scan_permissions'] = $entry['permissions']; $entry['permissions'] &= $this->getACLPermissionsForPath($entry['path'], $rules); @@ -55,30 +54,30 @@ protected function formatCacheEntry($entry, array $rules = []) { return $entry; } - public function getFolderContentsById($fileId) { + public function getFolderContentsById($fileId): array { $results = $this->getCache()->getFolderContentsById($fileId); $rules = $this->preloadEntries($results); - return array_filter(array_map(function ($entry) use ($rules) { + return array_filter(array_map(function (ICacheEntry $entry) use ($rules): ICacheEntry|false { return $this->formatCacheEntry($entry, $rules); }, $results)); } - public function search($pattern) { + public function search($pattern): array { $results = $this->getCache()->search($pattern); $this->preloadEntries($results); return array_filter(array_map($this->formatCacheEntry(...), $results)); } - public function searchByMime($mimetype) { + public function searchByMime($mimetype): array { $results = $this->getCache()->searchByMime($mimetype); $this->preloadEntries($results); return array_filter(array_map($this->formatCacheEntry(...), $results)); } - public function searchQuery(ISearchQuery $query) { + public function searchQuery(ISearchQuery $query): array { $results = $this->getCache()->searchQuery($query); $this->preloadEntries($results); @@ -87,10 +86,10 @@ public function searchQuery(ISearchQuery $query) { /** * @param ICacheEntry[] $entries - * @return Rule[][] + * @return array */ private function preloadEntries(array $entries): array { - $paths = array_map(function (ICacheEntry $entry) { + $paths = array_map(function (ICacheEntry $entry): string { return $entry->getPath(); }, $entries); diff --git a/lib/ACL/ACLManager.php b/lib/ACL/ACLManager.php index ebecf693b..167aa2efe 100644 --- a/lib/ACL/ACLManager.php +++ b/lib/ACL/ACLManager.php @@ -17,20 +17,17 @@ class ACLManager { private CappedMemoryCache $ruleCache; - /** @var callable */ - private $rootFolderProvider; public function __construct( - private RuleManager $ruleManager, + private RuleManager $ruleManager, private TrashManager $trashManager, private LoggerInterface $logger, - private IUser $user, - callable $rootFolderProvider, - private ?int $rootStorageId = null, - private bool $inheritMergePerUser = false, + private IUser $user, + private \Closure $rootFolderProvider, + private ?int $rootStorageId = null, + private bool $inheritMergePerUser = false, ) { $this->ruleCache = new CappedMemoryCache(); - $this->rootFolderProvider = $rootFolderProvider; } private function getRootStorageId(): int { @@ -84,7 +81,6 @@ private function getRules(array $paths, bool $cache = true): array { * * This contains the $path itself and any parent folder * - * @param string $path * @return string[] */ private function getRelevantPaths(string $path): array { @@ -147,9 +143,7 @@ public function getACLPermissionsForPath(string $path): int { } /** - * @param string $path * @param array $rules list of rules per path - * @return int */ public function getPermissionsForPathFromRules(string $path, array $rules): int { $path = ltrim($path, '/'); @@ -161,7 +155,6 @@ public function getPermissionsForPathFromRules(string $path, array $rules): int /** * @param array $rules list of rules per path, sorted parent first - * @return int */ private function calculatePermissionsForPath(array $rules): int { // given the following rules @@ -212,9 +205,6 @@ private function calculatePermissionsForPath(array $rules): int { /** * Get the combined "lowest" permissions for an entire directory tree - * - * @param string $path - * @return int */ public function getPermissionsForTree(string $path): int { $path = ltrim($path, '/'); diff --git a/lib/ACL/ACLManagerFactory.php b/lib/ACL/ACLManagerFactory.php index ccd93fd29..7a2e571eb 100644 --- a/lib/ACL/ACLManagerFactory.php +++ b/lib/ACL/ACLManagerFactory.php @@ -14,16 +14,13 @@ use Psr\Log\LoggerInterface; class ACLManagerFactory { - private $rootFolderProvider; - public function __construct( private RuleManager $ruleManager, private TrashManager $trashManager, private IConfig $config, private LoggerInterface $logger, - callable $rootFolderProvider, + private \Closure $rootFolderProvider, ) { - $this->rootFolderProvider = $rootFolderProvider; } public function getACLManager(IUser $user, ?int $rootStorageId = null): ACLManager { diff --git a/lib/ACL/ACLStorageWrapper.php b/lib/ACL/ACLStorageWrapper.php index 83845e5a8..3f71c7b95 100644 --- a/lib/ACL/ACLStorageWrapper.php +++ b/lib/ACL/ACLStorageWrapper.php @@ -9,14 +9,15 @@ 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\Storage\IStorage; class ACLStorageWrapper extends Wrapper { - /** @var ACLManager */ - private $aclManager; - /** @var bool */ - private $inShare; + private ACLManager $aclManager; + private bool $inShare; public function __construct($arguments) { parent::__construct($arguments); @@ -24,7 +25,7 @@ public function __construct($arguments) { $this->inShare = $arguments['in_share']; } - private function getACLPermissionsForPath(string $path) { + private function getACLPermissionsForPath(string $path): int { $permissions = $this->aclManager->getACLPermissionsForPath($path); // if there is no read permissions, than deny everything @@ -37,37 +38,37 @@ private function getACLPermissionsForPath(string $path) { return $canRead ? $permissions : 0; } - private function checkPermissions(string $path, int $permissions) { + private function checkPermissions(string $path, int $permissions): bool { return ($this->getACLPermissionsForPath($path) & $permissions) === $permissions; } - public function isReadable($path) { + public function isReadable($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_READ) && parent::isReadable($path); } - public function isUpdatable($path) { + public function isUpdatable($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_UPDATE) && parent::isUpdatable($path); } - public function isCreatable($path) { + public function isCreatable($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_CREATE) && parent::isCreatable($path); } - public function isDeletable($path) { + public function isDeletable($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_DELETE) && $this->canDeleteTree($path) && parent::isDeletable($path); } - public function isSharable($path) { + public function isSharable($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_SHARE) && parent::isSharable($path); } - public function getPermissions($path) { + public function getPermissions($path): int { return $this->storage->getPermissions($path) & $this->getACLPermissionsForPath($path); } - public function rename($source, $target) { + public function rename($source, $target): bool { if (strpos($source, $target) === 0) { $part = substr($source, strlen($target)); //This is a rename of the transfer file to the original file @@ -112,29 +113,29 @@ public function opendir($path) { return IteratorDirectory::wrap($items); } - public function copy($source, $target) { + public function copy($source, $target): bool { $permissions = $this->file_exists($target) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; return $this->checkPermissions($target, $permissions) && $this->checkPermissions($source, Constants::PERMISSION_READ) && parent::copy($source, $target); } - public function touch($path, $mtime = null) { + public function touch($path, $mtime = null): bool { $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; return $this->checkPermissions($path, $permissions) && parent::touch($path, $mtime); } - public function mkdir($path) { + public function mkdir($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_CREATE) && parent::mkdir($path); } - public function rmdir($path) { + public function rmdir($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_DELETE) && $this->canDeleteTree($path) && parent::rmdir($path); } - public function unlink($path) { + public function unlink($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_DELETE) && $this->canDeleteTree($path) && parent::unlink($path); @@ -143,15 +144,12 @@ public function unlink($path) { /** * When deleting we need to ensure that there is no file inside the folder being deleted that misses delete permissions * This check is fairly expensive so we only do it for the actual delete and not metadata operations - * - * @param string $path - * @return int */ private function canDeleteTree(string $path): int { return $this->aclManager->getPermissionsForTree($path) & Constants::PERMISSION_DELETE; } - public function file_put_contents($path, $data) { + public function file_put_contents($path, $data): int|float|false { $permissions = $this->file_exists($path) ? Constants::PERMISSION_UPDATE : Constants::PERMISSION_CREATE; return $this->checkPermissions($path, $permissions) ? parent::file_put_contents($path, $data) : false; } @@ -172,13 +170,11 @@ public function writeStream(string $path, $stream, ?int $size = null): int { } /** - * get a cache instance for the storage - * + * @inheritDoc * @param string $path - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the cache - * @return \OCP\Files\Cache\ICache + * @param ?IStorage $storage */ - public function getCache($path = '', $storage = null) { + public function getCache($path = '', $storage = null): ICache { if (!$storage) { $storage = $this; } @@ -188,7 +184,7 @@ public function getCache($path = '', $storage = null) { return new ACLCacheWrapper($sourceCache, $this->aclManager, $this->inShare); } - public function getMetaData($path) { + public function getMetaData($path): ?array { $data = parent::getMetaData($path); if ($data && isset($data['permissions'])) { @@ -199,7 +195,12 @@ public function getMetaData($path) { return $data; } - public function getScanner($path = '', $storage = null) { + /** + * @inheritDoc + * @param string $path + * @param ?IStorage $storage + */ + public function getScanner($path = '', $storage = null): Scanner { if (!$storage) { $storage = $this->storage; } @@ -207,17 +208,17 @@ public function getScanner($path = '', $storage = null) { return parent::getScanner($path, $storage); } - public function is_dir($path) { + public function is_dir($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_READ) && parent::is_dir($path); } - public function is_file($path) { + public function is_file($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_READ) && parent::is_file($path); } - public function stat($path) { + public function stat($path): array|bool { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -225,7 +226,7 @@ public function stat($path) { return parent::stat($path); } - public function filetype($path) { + public function filetype($path): string|bool { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -241,12 +242,12 @@ public function filesize($path): false|int|float { return parent::filesize($path); } - public function file_exists($path) { + public function file_exists($path): bool { return $this->checkPermissions($path, Constants::PERMISSION_READ) && parent::file_exists($path); } - public function filemtime($path) { + public function filemtime($path): int|bool { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -254,7 +255,7 @@ public function filemtime($path) { return parent::filemtime($path); } - public function file_get_contents($path) { + public function file_get_contents($path): string|false { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -262,7 +263,7 @@ public function file_get_contents($path) { return parent::file_get_contents($path); } - public function getMimeType($path) { + public function getMimeType($path): string|bool { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -270,7 +271,7 @@ public function getMimeType($path) { return parent::getMimeType($path); } - public function hash($type, $path, $raw = false) { + public function hash($type, $path, $raw = false): string|bool { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -278,7 +279,7 @@ public function hash($type, $path, $raw = false) { return parent::hash($type, $path, $raw); } - public function getETag($path) { + public function getETag($path): string|false { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -286,7 +287,7 @@ public function getETag($path) { return parent::getETag($path); } - public function getDirectDownload($path) { + public function getDirectDownload($path): array|bool { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } diff --git a/lib/ACL/Rule.php b/lib/ACL/Rule.php index 2a9828bb2..6c18b4c72 100644 --- a/lib/ACL/Rule.php +++ b/lib/ACL/Rule.php @@ -32,19 +32,19 @@ class Rule implements XmlSerializable, XmlDeserializable, \JsonSerializable { 'share' => Constants::PERMISSION_SHARE, ]; - private $userMapping; - private $fileId; - - // for every permission type a rule can either allow, deny or inherit - // these 3 values are stored as 2 bitmaps, one that masks out all inherit values (1 -> set permission, 0 -> inherit) - // and one that specifies the permissions to set for non inherited values (1-> allow, 0 -> deny) - private $mask; - private $permissions; - - public function __construct(IUserMapping $userMapping, int $fileId, int $mask, int $permissions) { - $this->userMapping = $userMapping; - $this->fileId = $fileId; - $this->mask = $mask; + private int $permissions; + + /** + * @param int $mask for every permission type a rule can either allow, deny or inherit + * these 3 values are stored as 2 bitmaps, one that masks out all inherit values (1 -> set permission, 0 -> inherit) + * and one that specifies the permissions to set for non inherited values (1-> allow, 0 -> deny) + */ + public function __construct( + private IUserMapping $userMapping, + private int $fileId, + private int $mask, + int $permissions, + ) { $this->permissions = $permissions & $mask; } @@ -68,9 +68,6 @@ public function getPermissions(): int { * Apply this rule to an existing permission set, returning the resulting permissions * * All permissions included in the current mask will overwrite the existing permissions - * - * @param int $permissions - * @return int */ public function applyPermissions(int $permissions): int { $invertedMask = ~$this->mask; @@ -85,10 +82,7 @@ public function applyPermissions(int $permissions): int { return $permissions | $allowMask; } - /** - * @return void - */ - public function xmlSerialize(Writer $writer) { + public function xmlSerialize(Writer $writer): void { $data = [ self::ACL => [ self::MAPPING_TYPE => $this->getUserMapping()->getType(), @@ -101,8 +95,7 @@ public function xmlSerialize(Writer $writer) { $writer->write($data); } - #[\ReturnTypeWillChange] - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'mapping' => [ 'type' => $this->getUserMapping()->getType(), @@ -129,17 +122,14 @@ public static function xmlDeserialize(Reader $reader): Rule { /** * merge multiple rules that apply on the same file where allow overwrites deny - * - * @param array $rules - * @return Rule */ public static function mergeRules(array $rules): Rule { // or'ing the masks to get a new mask that masks all set permissions - $mask = array_reduce($rules, function (int $mask, Rule $rule) { + $mask = array_reduce($rules, function (int $mask, Rule $rule): int { return $mask | $rule->getMask(); }, 0); // or'ing the permissions combines them with allow overwriting deny - $permissions = array_reduce($rules, function (int $permissions, Rule $rule) { + $permissions = array_reduce($rules, function (int $permissions, Rule $rule): int { return $permissions | $rule->getPermissions(); }, 0); @@ -155,9 +145,6 @@ public static function mergeRules(array $rules): Rule { * apply a new rule on top of the existing * * All non-inherit fields of the new rule will overwrite the current permissions - * - * @param array $rules - * @return void */ public function applyRule(Rule $rule): void { $this->permissions = $rule->applyPermissions($this->permissions); @@ -166,8 +153,6 @@ public function applyRule(Rule $rule): void { /** * Create a default, no-op rule - * - * @return Rule */ public static function defaultRule(): Rule { return new Rule( diff --git a/lib/ACL/RuleManager.php b/lib/ACL/RuleManager.php index f442373e8..a4b1369b4 100644 --- a/lib/ACL/RuleManager.php +++ b/lib/ACL/RuleManager.php @@ -10,6 +10,7 @@ use OCA\GroupFolders\ACL\UserMapping\IUserMapping; use OCA\GroupFolders\ACL\UserMapping\IUserMappingManager; +use OCP\DB\QueryBuilder\ICompositeExpression; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\IDBConnection; @@ -17,14 +18,11 @@ use OCP\Log\Audit\CriticalActionPerformedEvent; class RuleManager { - private IDBConnection $connection; - private IUserMappingManager $userMappingManager; - private IEventDispatcher $eventDispatcher; - - public function __construct(IDBConnection $connection, IUserMappingManager $userMappingManager, IEventDispatcher $eventDispatcher) { - $this->connection = $connection; - $this->userMappingManager = $userMappingManager; - $this->eventDispatcher = $eventDispatcher; + public function __construct( + private IDBConnection $connection, + private IUserMappingManager $userMappingManager, + private IEventDispatcher $eventDispatcher, + ) { } private function createRule(array $data): ?Rule { @@ -42,9 +40,8 @@ private function createRule(array $data): ?Rule { } /** - * @param IUser $user * @param int[] $fileIds - * @return (Rule[])[] [$fileId => Rule[]] + * @return array */ public function getRulesForFilesById(IUser $user, array $fileIds): array { $userMappings = $this->userMappingManager->getMappingsForUser($user); @@ -53,7 +50,7 @@ public function getRulesForFilesById(IUser $user, array $fileIds): array { $query->select(['fileid', 'mapping_type', 'mapping_id', 'mask', 'permissions']) ->from('group_folders_acl') ->where($query->expr()->in('fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))) - ->andWhere($query->expr()->orX(...array_map(function (IUserMapping $userMapping) use ($query) { + ->andWhere($query->expr()->orX(...array_map(function (IUserMapping $userMapping) use ($query): ICompositeExpression { return $query->expr()->andX( $query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())), $query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId())) @@ -78,10 +75,8 @@ public function getRulesForFilesById(IUser $user, array $fileIds): array { } /** - * @param IUser $user - * @param int $storageId * @param string[] $filePaths - * @return (Rule[])[] [$path => Rule[]] + * @return array */ public function getRulesForFilesByPath(IUser $user, int $storageId, array $filePaths): array { $userMappings = $this->userMappingManager->getMappingsForUser($user); @@ -98,7 +93,7 @@ public function getRulesForFilesByPath(IUser $user, int $storageId, array $fileP ->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid')) ->where($query->expr()->in('path_hash', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY))) ->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) - ->andWhere($query->expr()->orX(...array_map(function (IUserMapping $userMapping) use ($query) { + ->andWhere($query->expr()->orX(...array_map(function (IUserMapping $userMapping) use ($query): ICompositeExpression { return $query->expr()->andX( $query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())), $query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId())) @@ -117,10 +112,7 @@ public function getRulesForFilesByPath(IUser $user, int $storageId, array $fileP } /** - * @param IUser $user - * @param int $storageId - * @param string $parent - * @return (Rule[])[] [$path => Rule[]] + * @return array */ public function getRulesForFilesByParent(IUser $user, int $storageId, string $parent): array { $userMappings = $this->userMappingManager->getMappingsForUser($user); @@ -141,7 +133,7 @@ public function getRulesForFilesByParent(IUser $user, int $storageId, string $pa $query->expr()->isNull('mapping_type'), $query->expr()->isNull('mapping_id') ), - ...array_map(function (IUserMapping $userMapping) use ($query) { + ...array_map(function (IUserMapping $userMapping) use ($query): ICompositeExpression { return $query->expr()->andX( $query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())), $query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId())) @@ -180,12 +172,11 @@ private function getId(int $storageId, string $path): int { } /** - * @param int $storageId * @param string[] $filePaths - * @return (Rule[])[] [$path => Rule[]] + * @return array */ public function getAllRulesForPaths(int $storageId, array $filePaths): array { - $hashes = array_map(function (string $path) { + $hashes = array_map(function (string $path): string { return md5(trim($path, '/')); }, $filePaths); $query = $this->connection->getQueryBuilder(); @@ -216,9 +207,7 @@ private function rulesByPath(array $rows, array $result = []): array { } /** - * @param int $storageId - * @param string $prefix - * @return (Rule[])[] [$path => Rule[]] + * @return array */ public function getAllRulesForPrefix(int $storageId, string $prefix): array { $query = $this->connection->getQueryBuilder(); @@ -237,10 +226,7 @@ public function getAllRulesForPrefix(int $storageId, string $prefix): array { } /** - * @param IUser $user - * @param int $storageId - * @param string $prefix - * @return array (Rule[])[] [$path => Rule[]] + * @return array */ public function getRulesForPrefix(IUser $user, int $storageId, string $prefix): array { $userMappings = $this->userMappingManager->getMappingsForUser($user); @@ -254,7 +240,7 @@ public function getRulesForPrefix(IUser $user, int $storageId, string $prefix): $query->expr()->eq('path_hash', $query->createNamedParameter(md5($prefix))) )) ->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) - ->andWhere($query->expr()->orX(...array_map(function (IUserMapping $userMapping) use ($query) { + ->andWhere($query->expr()->orX(...array_map(function (IUserMapping $userMapping) use ($query): ICompositeExpression { return $query->expr()->andX( $query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())), $query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId())) diff --git a/lib/ACL/UserMapping/IUserMapping.php b/lib/ACL/UserMapping/IUserMapping.php index 895fdabd6..f86d7fbc4 100644 --- a/lib/ACL/UserMapping/IUserMapping.php +++ b/lib/ACL/UserMapping/IUserMapping.php @@ -9,7 +9,7 @@ namespace OCA\GroupFolders\ACL\UserMapping; interface IUserMapping { - /** @return 'user'|'group' */ + /** @return 'user'|'group'|'dummy' */ public function getType(): string; public function getId(): string; diff --git a/lib/ACL/UserMapping/IUserMappingManager.php b/lib/ACL/UserMapping/IUserMappingManager.php index dd3f6ff72..373aba8cf 100644 --- a/lib/ACL/UserMapping/IUserMappingManager.php +++ b/lib/ACL/UserMapping/IUserMappingManager.php @@ -12,16 +12,10 @@ interface IUserMappingManager { /** - * @param IUser $user * @param bool $userAssignable whether to include mappings that are assignable by non admin users * @return IUserMapping[] */ public function getMappingsForUser(IUser $user, bool $userAssignable = true): array; - /** - * @param string $type - * @param string $id - * @return IUserMapping|null - */ public function mappingFromId(string $type, string $id): ?IUserMapping; } diff --git a/lib/ACL/UserMapping/UserMapping.php b/lib/ACL/UserMapping/UserMapping.php index e2f87ef6a..2a9b2e207 100644 --- a/lib/ACL/UserMapping/UserMapping.php +++ b/lib/ACL/UserMapping/UserMapping.php @@ -9,18 +9,19 @@ namespace OCA\GroupFolders\ACL\UserMapping; class UserMapping implements IUserMapping { - /** @var 'user'|'group' * */ - private string $type; - private string $id; private string $displayName; - public function __construct(string $type, string $id, ?string $displayName = null) { - $this->type = $type; - $this->id = $id; + /** + * @param 'user'|'group'|'dummy' $type + */ + public function __construct( + private string $type, + private string $id, + ?string $displayName = null, + ) { $this->displayName = $displayName ?? $id; } - /** @return 'user'|'group' */ public function getType(): string { return $this->type; } diff --git a/lib/ACL/UserMapping/UserMappingManager.php b/lib/ACL/UserMapping/UserMappingManager.php index 6c3c9e7e6..3a767a013 100644 --- a/lib/ACL/UserMapping/UserMappingManager.php +++ b/lib/ACL/UserMapping/UserMappingManager.php @@ -14,16 +14,14 @@ use OCP\IUserManager; class UserMappingManager implements IUserMappingManager { - private $groupManager; - private $userManager; - - public function __construct(IGroupManager $groupManager, IUserManager $userManager) { - $this->groupManager = $groupManager; - $this->userManager = $userManager; + public function __construct( + private IGroupManager $groupManager, + private IUserManager $userManager, + ) { } public function getMappingsForUser(IUser $user, bool $userAssignable = true): array { - $groupMappings = array_values(array_map(function (IGroup $group) { + $groupMappings = array_values(array_map(function (IGroup $group): UserMapping { return new UserMapping('group', $group->getGID(), $group->getDisplayName()); }, $this->groupManager->getUserGroups($user))); diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 12d360414..b36934212 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -41,6 +41,7 @@ use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\BackgroundJob\TimedJob; use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Events\Node\NodeRenamedEvent; use OCP\Files\Folder; @@ -52,9 +53,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\IGroup; -use OCP\IGroupManager; use OCP\IRequest; -use OCP\ISession; use OCP\IUserManager; use OCP\IUserSession; use Psr\Container\ContainerInterface; @@ -86,9 +85,12 @@ public function register(IRegistrationContext $context): void { /** @var IRootFolder $rootFolder */ $rootFolder = $c->get(IRootFolder::class); - return new LazyFolder($rootFolder, function () use ($rootFolder) { + return new LazyFolder($rootFolder, function () use ($rootFolder): Folder { try { - return $rootFolder->get('__groupfolders'); + /** @var Folder $folder */ + $folder = $rootFolder->get('__groupfolders'); + + return $folder; } catch (NotFoundException $e) { return $rootFolder->newFolder('__groupfolders'); } @@ -106,13 +108,11 @@ public function register(IRegistrationContext $context): void { $enableEncryption = $config->getAppValue('groupfolders', 'enable_encryption', 'false') === 'true'; return new MountProvider( - $c->get(IGroupManager::class), $c->get(FolderManager::class), $rootProvider, $c->get(ACLManagerFactory::class), $c->get(IUserSession::class), $c->get(IRequest::class), - $c->get(ISession::class), $c->get(IMountProviderCollection::class), $c->get(IDBConnection::class), $c->get(ICacheFactory::class)->createLocal('groupfolders'), @@ -185,7 +185,7 @@ public function register(IRegistrationContext $context): void { return new ExpireGroupBase(); }); - $context->registerService(\OCA\GroupFolders\BackgroundJob\ExpireGroupVersions::class, function (ContainerInterface $c) { + $context->registerService(\OCA\GroupFolders\BackgroundJob\ExpireGroupVersions::class, function (ContainerInterface $c): TimedJob { if (interface_exists(\OCA\Files_Versions\Versions\IVersionBackend::class)) { return new ExpireGroupVersionsJob( $c->get(ITimeFactory::class), @@ -199,7 +199,7 @@ public function register(IRegistrationContext $context): void { return new ExpireGroupPlaceholder($c->get(ITimeFactory::class)); }); - $context->registerService(\OCA\GroupFolders\BackgroundJob\ExpireGroupTrash::class, function (ContainerInterface $c) { + $context->registerService(\OCA\GroupFolders\BackgroundJob\ExpireGroupTrash::class, function (ContainerInterface $c): TimedJob { if (interface_exists(\OCA\Files_Trashbin\Trash\ITrashBackend::class)) { return new ExpireGroupTrashJob( $c->get(TrashBackend::class), diff --git a/lib/AppInfo/Capabilities.php b/lib/AppInfo/Capabilities.php index fdf6b428b..bed591df2 100644 --- a/lib/AppInfo/Capabilities.php +++ b/lib/AppInfo/Capabilities.php @@ -14,14 +14,11 @@ use OCP\IUserSession; class Capabilities implements ICapability { - private IUserSession $userSession; - private FolderManager $folderManager; - private IAppManager $appManager; - - public function __construct(IUserSession $userSession, FolderManager $folderManager, IAppManager $appManager) { - $this->userSession = $userSession; - $this->folderManager = $folderManager; - $this->appManager = $appManager; + public function __construct( + private IUserSession $userSession, + private FolderManager $folderManager, + private IAppManager $appManager, + ) { } public function getCapabilities(): array { diff --git a/lib/AuthorizedAdminSettingMiddleware.php b/lib/AuthorizedAdminSettingMiddleware.php index b5c2d54a5..be600b5d2 100644 --- a/lib/AuthorizedAdminSettingMiddleware.php +++ b/lib/AuthorizedAdminSettingMiddleware.php @@ -9,6 +9,7 @@ use Exception; use OCA\GroupFolders\Service\DelegationService; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; @@ -17,29 +18,17 @@ use OCP\IRequest; class AuthorizedAdminSettingMiddleware extends Middleware { - private DelegationService $delegatedService; - private IControllerMethodReflector $reflector; - private IRequest $request; - public function __construct( - DelegationService $delegatedService, - IControllerMethodReflector $reflector, - IRequest $request, + private DelegationService $delegatedService, + private IControllerMethodReflector $reflector, + private IRequest $request, ) { - $this->delegatedService = $delegatedService; - $this->reflector = $reflector; - $this->request = $request; } /** - * - * {@inheritDoc} - * @see \OCP\AppFramework\Middleware::beforeController() - * * Throws an error when the user is not allowed to use the app's APIs - * */ - public function beforeController($controller, $methodName) { + public function beforeController(Controller $controller, string $methodName): void { if ($this->reflector->hasAnnotation('RequireGroupFolderAdmin')) { if (!$this->delegatedService->hasApiAccess()) { throw new Exception('Logged in user must be an admin, a sub admin or gotten special right to access this setting'); @@ -47,13 +36,7 @@ public function beforeController($controller, $methodName) { } } - /** - * - * {@inheritDoc} - * @see \OCP\AppFramework\Middleware::afterException() - * - */ - public function afterException($controller, $methodName, \Exception $exception): Response { + public function afterException(Controller $controller, string $methodName, Exception $exception): Response { if (stripos($this->request->getHeader('Accept'), 'html') === false) { $response = new JSONResponse( ['message' => $exception->getMessage()], diff --git a/lib/BackgroundJob/ExpireGroupPlaceholder.php b/lib/BackgroundJob/ExpireGroupPlaceholder.php index 44f3dd858..907a54af5 100644 --- a/lib/BackgroundJob/ExpireGroupPlaceholder.php +++ b/lib/BackgroundJob/ExpireGroupPlaceholder.php @@ -18,7 +18,7 @@ public function __construct(ITimeFactory $timeFactory) { $this->setInterval(60 * 60 * 99999999); } - protected function run($argument) { + protected function run(mixed $argument): void { // noop } } diff --git a/lib/BackgroundJob/ExpireGroupTrash.php b/lib/BackgroundJob/ExpireGroupTrash.php index 1532f4f69..4e538b31c 100644 --- a/lib/BackgroundJob/ExpireGroupTrash.php +++ b/lib/BackgroundJob/ExpireGroupTrash.php @@ -15,26 +15,18 @@ use OCP\IConfig; class ExpireGroupTrash extends TimedJob { - private TrashBackend $trashBackend; - private Expiration $expiration; - private IConfig $config; - public function __construct( - TrashBackend $trashBackend, - Expiration $expiration, - IConfig $config, + private TrashBackend $trashBackend, + private Expiration $expiration, + private IConfig $config, ITimeFactory $timeFactory, ) { parent::__construct($timeFactory); // Run once per hour $this->setInterval(60 * 60); - - $this->trashBackend = $trashBackend; - $this->expiration = $expiration; - $this->config = $config; } - protected function run($argument) { + protected function run(mixed $argument): void { $backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes'); if ($backgroundJob === 'no') { return; diff --git a/lib/BackgroundJob/ExpireGroupVersions.php b/lib/BackgroundJob/ExpireGroupVersions.php index c87a2e1dd..d1b07519b 100644 --- a/lib/BackgroundJob/ExpireGroupVersions.php +++ b/lib/BackgroundJob/ExpireGroupVersions.php @@ -30,15 +30,14 @@ public function __construct( $this->setInterval(60 * 60); // But don't run if still running $this->setAllowParallelRuns(false); - - $this->expireManager = $expireManager; } /** + * @inheritDoc * Expiring groupfolder versions can be quite expensive. * We need to limit the amount of folders we expire per run. */ - protected function run($argument) { + protected function run(mixed $argument): void { $lastFolder = $this->appConfig->getValueInt(Application::APP_ID, 'cron_last_folder_index', 0); $folders = $this->folderManager->getAllFolders(); @@ -64,7 +63,7 @@ protected function run($argument) { // Determine the set of folders to process $folderSet = array_slice($folders, $lastFolder, $toDo); - $folderIDs = array_map(function ($folder) { + $folderIDs = array_map(function (array $folder): int { return $folder['id']; }, $folderSet); diff --git a/lib/Command/ACL.php b/lib/Command/ACL.php index 567e4f034..e6b69f65f 100644 --- a/lib/Command/ACL.php +++ b/lib/Command/ACL.php @@ -24,25 +24,18 @@ use Symfony\Component\Console\Output\OutputInterface; class ACL extends FolderCommand { - private RuleManager $ruleManager; - private ACLManagerFactory $aclManagerFactory; - private IUserManager $userManager; - public function __construct( FolderManager $folderManager, IRootFolder $rootFolder, - RuleManager $ruleManager, + private RuleManager $ruleManager, MountProvider $mountProvider, - ACLManagerFactory $aclManagerFactory, - IUserManager $userManager, + private ACLManagerFactory $aclManagerFactory, + private IUserManager $userManager, ) { parent::__construct($folderManager, $rootFolder, $mountProvider); - $this->ruleManager = $ruleManager; - $this->aclManagerFactory = $aclManagerFactory; - $this->userManager = $userManager; } - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:permissions') ->setDescription('Configure advanced permissions for a configured group folder') @@ -59,7 +52,7 @@ protected function configure() { parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $folder = $this->getFolder($input, $output); if ($folder === null) { return -1; @@ -191,7 +184,7 @@ private function printPermissions(InputInterface $input, OutputInterface $output switch ($outputFormat) { case parent::OUTPUT_FORMAT_JSON: case parent::OUTPUT_FORMAT_JSON_PRETTY: - $paths = array_map(function ($rawPath) use ($jailPathLength) { + $paths = array_map(function (string $rawPath) use ($jailPathLength): string { $path = substr($rawPath, $jailPathLength); return $path ?: '/'; }, array_keys($rules)); @@ -201,12 +194,12 @@ private function printPermissions(InputInterface $input, OutputInterface $output $output->writeln(json_encode($items, $outputFormat === parent::OUTPUT_FORMAT_JSON_PRETTY ? JSON_PRETTY_PRINT : 0)); break; default: - $items = array_map(function (array $rulesForPath, string $path) use ($jailPathLength) { + $items = array_map(function (array $rulesForPath, string $path) use ($jailPathLength): array { /** @var Rule[] $rulesForPath */ - $mappings = array_map(function (Rule $rule) { + $mappings = array_map(function (Rule $rule): string { return $rule->getUserMapping()->getType() . ': ' . $rule->getUserMapping()->getId(); }, $rulesForPath); - $permissions = array_map(function (Rule $rule) { + $permissions = array_map(function (Rule $rule): string { return $rule->formatPermissions(); }, $rulesForPath); $formattedPath = substr($path, $jailPathLength); @@ -217,7 +210,7 @@ private function printPermissions(InputInterface $input, OutputInterface $output 'permissions' => implode("\n", $permissions), ]; }, $rules, array_keys($rules)); - usort($items, function ($a, $b) { + usort($items, function (array $a, array $b): int { return $a['path'] <=> $b['path']; }); diff --git a/lib/Command/Create.php b/lib/Command/Create.php index 3ce3bd897..0020afa27 100644 --- a/lib/Command/Create.php +++ b/lib/Command/Create.php @@ -15,14 +15,13 @@ use Symfony\Component\Console\Output\OutputInterface; class Create extends Base { - private FolderManager $folderManager; - - public function __construct(FolderManager $folderManager) { + public function __construct( + private FolderManager $folderManager, + ) { parent::__construct(); - $this->folderManager = $folderManager; } - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:create') ->setDescription('Create a new group folder') @@ -30,7 +29,7 @@ protected function configure() { parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $id = $this->folderManager->createFolder($input->getArgument('name')); $output->writeln((string)$id); diff --git a/lib/Command/Delete.php b/lib/Command/Delete.php index 35031d00c..228db84fd 100644 --- a/lib/Command/Delete.php +++ b/lib/Command/Delete.php @@ -15,7 +15,7 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; class Delete extends FolderCommand { - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:delete') ->setDescription('Delete group folder') @@ -24,7 +24,7 @@ protected function configure() { parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $folder = $this->getFolder($input, $output); if ($folder === null) { return -1; diff --git a/lib/Command/ExpireGroup/ExpireGroupTrash.php b/lib/Command/ExpireGroup/ExpireGroupTrash.php index f77a64373..99ab7809c 100644 --- a/lib/Command/ExpireGroup/ExpireGroupTrash.php +++ b/lib/Command/ExpireGroup/ExpireGroupTrash.php @@ -14,16 +14,11 @@ use Symfony\Component\Console\Output\OutputInterface; class ExpireGroupTrash extends ExpireGroupBase { - private TrashBackend $trashBackend; - private Expiration $expiration; - public function __construct( - TrashBackend $trashBackend, - Expiration $expiration, + private TrashBackend $trashBackend, + private Expiration $expiration, ) { parent::__construct(); - $this->trashBackend = $trashBackend; - $this->expiration = $expiration; } protected function configure(): void { diff --git a/lib/Command/ExpireGroup/ExpireGroupVersions.php b/lib/Command/ExpireGroup/ExpireGroupVersions.php index 43d9ca99f..b4d8031eb 100644 --- a/lib/Command/ExpireGroup/ExpireGroupVersions.php +++ b/lib/Command/ExpireGroup/ExpireGroupVersions.php @@ -17,13 +17,10 @@ * Trigger expiry of versions for files stored in group folders. */ class ExpireGroupVersions extends ExpireGroupBase { - protected GroupVersionsExpireManager $expireManager; - public function __construct( - GroupVersionsExpireManager $expireManager, + private GroupVersionsExpireManager $expireManager, ) { parent::__construct(); - $this->expireManager = $expireManager; } protected function configure(): void { @@ -43,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln("Expiring version $id for '$file'"); }); - $this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteFile', function ($id) use ($output): void { + $this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteFile', function (int $id) use ($output): void { $output->writeln("Cleaning up versions for no longer existing file with id $id"); }); diff --git a/lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php b/lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php index 9ac17b789..4e27e1879 100644 --- a/lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php +++ b/lib/Command/ExpireGroup/ExpireGroupVersionsTrash.php @@ -15,17 +15,12 @@ use Symfony\Component\Console\Output\OutputInterface; class ExpireGroupVersionsTrash extends ExpireGroupVersions { - private TrashBackend $trashBackend; - private Expiration $expiration; - public function __construct( GroupVersionsExpireManager $expireManager, - TrashBackend $trashBackend, - Expiration $expiration, + private TrashBackend $trashBackend, + private Expiration $expiration, ) { parent::__construct($expireManager); - $this->trashBackend = $trashBackend; - $this->expiration = $expiration; } protected function configure(): void { diff --git a/lib/Command/ExpireGroupVersionsPlaceholder.php b/lib/Command/ExpireGroupVersionsPlaceholder.php index 97ef60eaa..cb3a8be52 100644 --- a/lib/Command/ExpireGroupVersionsPlaceholder.php +++ b/lib/Command/ExpireGroupVersionsPlaceholder.php @@ -13,18 +13,14 @@ use Symfony\Component\Console\Output\OutputInterface; class ExpireGroupVersionsPlaceholder extends Base { - public function __construct() { - parent::__construct(); - } - - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:expire') ->setDescription('Trigger expiry of versions for files stored in group folders'); parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('groupfolder version handling is only supported with Nextcloud 15 and up'); return 0; } diff --git a/lib/Command/FolderCommand.php b/lib/Command/FolderCommand.php index c402041fe..8ebb8a3fa 100644 --- a/lib/Command/FolderCommand.php +++ b/lib/Command/FolderCommand.php @@ -19,15 +19,13 @@ * Base command for commands asking the user for a folder id. */ abstract class FolderCommand extends Base { - protected FolderManager $folderManager; - protected IRootFolder $rootFolder; - protected MountProvider $mountProvider; - public function __construct(FolderManager $folderManager, IRootFolder $rootFolder, MountProvider $mountProvider) { + public function __construct( + protected FolderManager $folderManager, + protected IRootFolder $rootFolder, + protected MountProvider $mountProvider, + ) { parent::__construct(); - $this->folderManager = $folderManager; - $this->rootFolder = $rootFolder; - $this->mountProvider = $mountProvider; } /** diff --git a/lib/Command/Group.php b/lib/Command/Group.php index 2fe06b46d..f82d61250 100644 --- a/lib/Command/Group.php +++ b/lib/Command/Group.php @@ -25,14 +25,17 @@ class Group extends FolderCommand { 'share' => Constants::PERMISSION_SHARE, 'delete' => Constants::PERMISSION_DELETE, ]; - private IGroupManager $groupManager; - public function __construct(FolderManager $folderManager, IRootFolder $rootFolder, IGroupManager $groupManager, MountProvider $mountProvider) { + public function __construct( + FolderManager $folderManager, + IRootFolder $rootFolder, + private IGroupManager $groupManager, + MountProvider $mountProvider, + ) { parent::__construct($folderManager, $rootFolder, $mountProvider); - $this->groupManager = $groupManager; } - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:group') ->setDescription('Edit the groups that have access to a group folder') @@ -44,7 +47,7 @@ protected function configure() { parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $folder = $this->getFolder($input, $output); if ($folder === null) { return -1; diff --git a/lib/Command/ListCommand.php b/lib/Command/ListCommand.php index 6825a4d27..86229f9f6 100644 --- a/lib/Command/ListCommand.php +++ b/lib/Command/ListCommand.php @@ -28,20 +28,17 @@ class ListCommand extends Base { Constants::PERMISSION_DELETE => 'delete' ]; - private FolderManager $folderManager; - private IRootFolder $rootFolder; - private IGroupManager $groupManager; - private IUserManager $userManager; - public function __construct(FolderManager $folderManager, IRootFolder $rootFolder, IGroupManager $groupManager, IUserManager $userManager) { + public function __construct( + private FolderManager $folderManager, + private IRootFolder $rootFolder, + private IGroupManager $groupManager, + private IUserManager $userManager, + ) { parent::__construct(); - $this->folderManager = $folderManager; - $this->rootFolder = $rootFolder; - $this->groupManager = $groupManager; - $this->userManager = $userManager; } - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:list') ->setDescription('List the configured group folders') @@ -49,7 +46,7 @@ protected function configure() { parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $userId = $input->getOption('user'); $groups = $this->groupManager->search(''); $groupNames = []; @@ -70,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $folders = $this->folderManager->getAllFoldersWithSize($rootStorageId); } - usort($folders, function ($a, $b) { + usort($folders, function (array $a, array $b): int { return $a['id'] - $b['id']; }); @@ -88,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { foreach ($folders as &$folder) { $folder['group_details'] = $folder['groups']; - $folder['groups'] = array_map(function (array $group) { + $folder['groups'] = array_map(function (array $group): int { return $group['permissions']; }, $folder['groups']); } @@ -108,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { }, array_keys($folder['groups']), array_values($folder['groups'])); $folder['groups'] = implode("\n", $groupStrings); $folder['acl'] = $folder['acl'] ? 'Enabled' : 'Disabled'; - $manageStrings = array_map(function ($manage) { + $manageStrings = array_map(function (array $manage): string { return $manage['id'] . ' (' . $manage['type'] . ')'; }, $folder['manage']); $folder['manage'] = implode("\n", $manageStrings); @@ -126,7 +123,7 @@ private function permissionsToString(int $permissions): string { return 'none'; } - return implode(', ', array_filter(self::PERMISSION_NAMES, function (int $possiblePermission) use ($permissions) { + return implode(', ', array_filter(self::PERMISSION_NAMES, function (int $possiblePermission) use ($permissions): int { return $possiblePermission & $permissions; }, ARRAY_FILTER_USE_KEY)); } diff --git a/lib/Command/Quota.php b/lib/Command/Quota.php index ccef5db2b..4d021d9de 100644 --- a/lib/Command/Quota.php +++ b/lib/Command/Quota.php @@ -14,7 +14,7 @@ use Symfony\Component\Console\Output\OutputInterface; class Quota extends FolderCommand { - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:quota') ->setDescription('Edit the quota of a configured group folder') @@ -23,7 +23,7 @@ protected function configure() { parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $folder = $this->getFolder($input, $output); if ($folder === null) { return -1; diff --git a/lib/Command/Scan.php b/lib/Command/Scan.php index 5d9266f4d..e1bbb938e 100644 --- a/lib/Command/Scan.php +++ b/lib/Command/Scan.php @@ -18,7 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface; class Scan extends FolderCommand { - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:scan') ->setDescription('Scan a group folder for outside changes') @@ -46,7 +46,7 @@ protected function configure() { parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { $folderId = $input->getArgument('folder_id'); $all = $input->getOption('all'); if ($folderId === null && !$all) { @@ -79,7 +79,6 @@ protected function execute(InputInterface $input, OutputInterface $output) { $recursive = !$input->getOption('shallow'); - $duration = 0; $stats = []; foreach ($folders as $folder) { $folderId = $folder['id']; @@ -94,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { return -1; } - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($output, &$statsRow): void { + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function (string $path) use ($output, &$statsRow): void { $output->writeln("\tFile\t/$path", OutputInterface::VERBOSITY_VERBOSE); $statsRow[2]++; // abortIfInterrupted doesn't exist in nc14 @@ -103,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { } }); - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($output, &$statsRow): void { + $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function (string $path) use ($output, &$statsRow): void { $output->writeln("\tFolder\t/$path", OutputInterface::VERBOSITY_VERBOSE); $statsRow[1]++; // abortIfInterrupted doesn't exist in nc14 @@ -127,12 +126,12 @@ protected function execute(InputInterface $input, OutputInterface $output) { 'Folder Id', 'Folders', 'Files', 'Elapsed time' ]; - $this->showSummary($headers, $stats, $output, $duration); + $this->showSummary($headers, $stats, $output); return 0; } - protected function showSummary($headers, $rows, OutputInterface $output, float $duration): void { + protected function showSummary(array $headers, array $rows, OutputInterface $output): void { $table = new Table($output); $table ->setHeaders($headers) diff --git a/lib/Command/Trashbin/Cleanup.php b/lib/Command/Trashbin/Cleanup.php index 29cc8694d..88b73a911 100644 --- a/lib/Command/Trashbin/Cleanup.php +++ b/lib/Command/Trashbin/Cleanup.php @@ -11,7 +11,6 @@ use OC\Core\Command\Base; use OCA\GroupFolders\Folder\FolderManager; use OCA\GroupFolders\Trash\TrashBackend; -use OCP\Files\IRootFolder; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -22,7 +21,7 @@ class Cleanup extends Base { private ?TrashBackend $trashBackend = null; private ?FolderManager $folderManager = null; - public function __construct(FolderManager $folderManager, IRootFolder $rootFolder) { + public function __construct(FolderManager $folderManager) { parent::__construct(); if (\OC::$server->getAppManager()->isEnabledForUser('files_trashbin')) { $this->trashBackend = \OCP\Server::get(TrashBackend::class); @@ -30,7 +29,7 @@ public function __construct(FolderManager $folderManager, IRootFolder $rootFolde } } - protected function configure() { + protected function configure(): void { $this ->setName('groupfolders:trashbin:cleanup') ->setDescription('Empty the groupfolder trashbin') @@ -39,7 +38,7 @@ protected function configure() { parent::configure(); } - protected function execute(InputInterface $input, OutputInterface $output) { + protected function execute(InputInterface $input, OutputInterface $output): int { if (!$this->trashBackend) { $output->writeln('files_trashbin is disabled: group folders trashbin is not available'); return -1; diff --git a/lib/Controller/FolderController.php b/lib/Controller/FolderController.php index b048ea700..b760098c7 100644 --- a/lib/Controller/FolderController.php +++ b/lib/Controller/FolderController.php @@ -25,48 +25,33 @@ use OCP\IUserSession; class FolderController extends OCSController { - private FolderManager $manager; - private MountProvider $mountProvider; - private IRootFolder $rootFolder; - private ?IUser $user = null; - private FoldersFilter $foldersFilter; - private DelegationService $delegationService; - private IGroupManager $groupManager; + private ?IUser $user; public function __construct( string $AppName, IRequest $request, - FolderManager $manager, - MountProvider $mountProvider, - IRootFolder $rootFolder, + private FolderManager $manager, + private MountProvider $mountProvider, + private IRootFolder $rootFolder, IUserSession $userSession, - FoldersFilter $foldersFilter, - DelegationService $delegationService, - IGroupManager $groupManager, + private FoldersFilter $foldersFilter, + private DelegationService $delegationService, + private IGroupManager $groupManager, ) { parent::__construct($AppName, $request); - $this->foldersFilter = $foldersFilter; - $this->manager = $manager; - $this->mountProvider = $mountProvider; - $this->rootFolder = $rootFolder; $this->user = $userSession->getUser(); - $this->registerResponder('xml', function ($data): V1Response { + $this->registerResponder('xml', function (DataResponse $data): V1Response { return $this->buildOCSResponseXML('xml', $data); }); - $this->delegationService = $delegationService; - $this->groupManager = $groupManager; } /** * Regular users can access their own folders, but they only get to see the permission for their own groups - * - * @param array $folder - * @return array|null */ private function filterNonAdminFolder(array $folder): ?array { $userGroups = $this->groupManager->getUserGroupIds($this->user); - $folder['groups'] = array_filter($folder['groups'], function (string $group) use ($userGroups) { + $folder['groups'] = array_filter($folder['groups'], function (string $group) use ($userGroups): bool { return in_array($group, $userGroups); }, ARRAY_FILTER_USE_KEY); if ($folder['groups']) { @@ -83,7 +68,7 @@ private function filterNonAdminFolder(array $folder): ?array { private function formatFolder(array $folder): array { // keep compatibility with the old 'groups' field $folder['group_details'] = $folder['groups']; - $folder['groups'] = array_map(function (array $group) { + $folder['groups'] = array_map(function (array $group): int { return $group['permissions']; }, $folder['groups']); @@ -309,11 +294,6 @@ public function renameFolder(int $id, string $mountpoint): DataResponse { /** * Overwrite response builder to customize xml handling to deal with spaces in folder names - * - * @param string $format json or xml - * @param DataResponse $data the data which should be transformed - * @return \OC\AppFramework\OCS\V1Response - * @since 8.1.0 */ private function buildOCSResponseXML(string $format, DataResponse $data): V1Response { /** @var array $folderData */ diff --git a/lib/DAV/ACLPlugin.php b/lib/DAV/ACLPlugin.php index 66c5beeda..18a154d52 100644 --- a/lib/DAV/ACLPlugin.php +++ b/lib/DAV/ACLPlugin.php @@ -11,6 +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\Folder\FolderManager; use OCA\GroupFolders\Mount\GroupMountPoint; use OCP\Constants; @@ -32,8 +33,8 @@ class ACLPlugin extends ServerPlugin { public const INHERITED_ACL_LIST = '{http://nextcloud.org/ns}inherited-acl-list'; public const GROUP_FOLDER_ID = '{http://nextcloud.org/ns}group-folder-id'; - private ?Server $server = null; - private ?IUser $user = null; + private ?Server $server; + private ?IUser $user; public function __construct( private RuleManager $ruleManager, @@ -94,7 +95,7 @@ public function propFind(PropFind $propFind, INode $node): void { return; } - $propFind->handle(self::ACL_LIST, function () use ($fileInfo, $mount) { + $propFind->handle(self::ACL_LIST, function () use ($fileInfo, $mount): array { $path = trim($mount->getSourcePath() . '/' . $fileInfo->getInternalPath(), '/'); if ($this->isAdmin($fileInfo->getPath())) { $rules = $this->ruleManager->getAllRulesForPaths($mount->getNumericStorageId(), [$path]); @@ -105,9 +106,9 @@ public function propFind(PropFind $propFind, INode $node): void { return array_pop($rules); }); - $propFind->handle(self::INHERITED_ACL_LIST, function () use ($fileInfo, $mount) { + $propFind->handle(self::INHERITED_ACL_LIST, function () use ($fileInfo, $mount): array { $parentInternalPaths = $this->getParents($fileInfo->getInternalPath()); - $parentPaths = array_map(function (string $internalPath) use ($mount) { + $parentPaths = array_map(function (string $internalPath) use ($mount): string { return trim($mount->getSourcePath() . '/' . $internalPath, '/'); }, $parentInternalPaths); if ($this->isAdmin($fileInfo->getPath())) { @@ -122,7 +123,6 @@ public function propFind(PropFind $propFind, INode $node): void { $mappings = []; foreach ($rulesByPath as $rules) { foreach ($rules as $rule) { - /** @var Rule $rule */ $mappingKey = $rule->getUserMapping()->getType() . '::' . $rule->getUserMapping()->getId(); if (!isset($mappings[$mappingKey])) { $mappings[$mappingKey] = $rule->getUserMapping(); @@ -141,7 +141,7 @@ public function propFind(PropFind $propFind, INode $node): void { } } - return array_map(function ($mapping, $permissions, $mask) use ($fileInfo) { + return array_map(function (UserMapping $mapping, int $permissions, int $mask) use ($fileInfo): Rule { return new Rule( $mapping, $fileInfo->getId(), @@ -151,16 +151,16 @@ public function propFind(PropFind $propFind, INode $node): void { }, $mappings, $inheritedPermissionsByMapping, $inheritedMaskByMapping); }); - $propFind->handle(self::GROUP_FOLDER_ID, function () use ($fileInfo) { + $propFind->handle(self::GROUP_FOLDER_ID, function () use ($fileInfo): int { return $this->folderManager->getFolderByPath($fileInfo->getPath()); }); - $propFind->handle(self::ACL_ENABLED, function () use ($fileInfo) { + $propFind->handle(self::ACL_ENABLED, function () use ($fileInfo): bool { $folderId = $this->folderManager->getFolderByPath($fileInfo->getPath()); return $this->folderManager->getFolderAclEnabled($folderId); }); - $propFind->handle(self::ACL_CAN_MANAGE, function () use ($fileInfo) { + $propFind->handle(self::ACL_CAN_MANAGE, function () use ($fileInfo): bool { return $this->isAdmin($fileInfo->getPath()); }); } @@ -178,7 +178,7 @@ public function propPatch(string $path, PropPatch $propPatch): void { } // Mapping the old property to the new property. - $propPatch->handle(self::ACL_LIST, function (array $rawRules) use ($path) { + $propPatch->handle(self::ACL_LIST, function (array $rawRules) use ($path): bool { $node = $this->server->tree->getNodeForPath($path); if (!$node instanceof Node) { return false; @@ -193,7 +193,7 @@ public function propPatch(string $path, PropPatch $propPatch): void { $path = trim($mount->getSourcePath() . '/' . $fileInfo->getInternalPath(), '/'); // populate fileid in rules - $rules = array_map(function (Rule $rule) use ($fileInfo) { + $rules = array_map(function (Rule $rule) use ($fileInfo): Rule { return new Rule( $rule->getUserMapping(), $fileInfo->getId(), @@ -202,7 +202,7 @@ public function propPatch(string $path, PropPatch $propPatch): void { ); }, $rawRules); - $formattedRules = array_map(function (Rule $rule) { + $formattedRules = array_map(function (Rule $rule): string { return $rule->getUserMapping()->getType() . ' ' . $rule->getUserMapping()->getDisplayName() . ': ' . $rule->formatPermissions(); }, $rules); if (count($formattedRules)) { @@ -221,14 +221,14 @@ public function propPatch(string $path, PropPatch $propPatch): void { $existingRules = array_reduce( $this->ruleManager->getAllRulesForPaths($mount->getNumericStorageId(), [$path]), - function (array $rules, array $rulesForPath) { + function (array $rules, array $rulesForPath): array { return array_merge($rules, $rulesForPath); }, [] ); - $deletedRules = array_udiff($existingRules, $rules, function ($obj_a, $obj_b) { + $deletedRules = array_udiff($existingRules, $rules, function (Rule $obj_a, Rule $obj_b): int { return ( $obj_a->getUserMapping()->getType() === $obj_b->getUserMapping()->getType() && $obj_a->getUserMapping()->getId() === $obj_b->getUserMapping()->getId() diff --git a/lib/DAV/GroupFolderNode.php b/lib/DAV/GroupFolderNode.php index fb2917302..481531651 100644 --- a/lib/DAV/GroupFolderNode.php +++ b/lib/DAV/GroupFolderNode.php @@ -13,11 +13,12 @@ use OCP\Files\FileInfo; class GroupFolderNode extends Directory { - private int $folderId; - - public function __construct(View $view, FileInfo $info, int $folderId) { + public function __construct( + View $view, + FileInfo $info, + private int $folderId, + ) { parent::__construct($view, $info); - $this->folderId = $folderId; } public function getFolderId(): int { diff --git a/lib/DAV/GroupFoldersHome.php b/lib/DAV/GroupFoldersHome.php index e6d4fad5f..fde1e7cdc 100644 --- a/lib/DAV/GroupFoldersHome.php +++ b/lib/DAV/GroupFoldersHome.php @@ -26,10 +26,7 @@ public function __construct( ) { } - /** - * @return never - */ - public function delete() { + public function delete(): never { throw new Forbidden(); } @@ -38,26 +35,19 @@ public function getName(): string { return $name; } - /** - * @return never - */ - public function setName($name) { + public function setName($name): never { throw new Forbidden('Permission denied to rename this folder'); } - public function createFile($name, $data = null) { + public function createFile($name, $data = null): never { throw new Forbidden('Not allowed to create files in this folder'); } - /** - * @return never - */ - public function createDirectory($name) { + public function createDirectory($name): never { throw new Forbidden('Permission denied to create folders in this folder'); } /** - * @param string $name * @return array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}|null */ private function getFolder(string $name): ?array { @@ -73,7 +63,6 @@ private function getFolder(string $name): ?array { /** * @param array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry} $folder - * @return GroupFolderNode */ private function getDirectoryForFolder(array $folder): GroupFolderNode { $userHome = '/' . $this->user->getUID() . '/files'; @@ -82,7 +71,7 @@ private function getDirectoryForFolder(array $folder): GroupFolderNode { return new GroupFolderNode(Filesystem::getView(), $node, $folder['folder_id']); } - public function getChild($name) { + public function getChild($name): GroupFolderNode { $folder = $this->getFolder($name); if ($folder) { return $this->getDirectoryForFolder($folder); @@ -92,7 +81,7 @@ public function getChild($name) { } /** - * @return (GroupFolderNode)[] + * @return GroupFolderNode[] */ public function getChildren(): array { $folders = $this->folderManager->getFoldersForUser($this->user, $this->rootFolder->getMountPoint()->getNumericStorageId()); diff --git a/lib/DAV/RootCollection.php b/lib/DAV/RootCollection.php index 947e5308f..e1d162af7 100644 --- a/lib/DAV/RootCollection.php +++ b/lib/DAV/RootCollection.php @@ -30,8 +30,6 @@ public function __construct( * The passed array contains principal information, and is guaranteed to * at least contain a uri item. Other properties may or may not be * supplied by the authentication backend. - * - * @param array $principalInfo */ public function getChildForPrincipal(array $principalInfo): GroupFoldersHome { [, $name] = \Sabre\Uri\split($principalInfo['uri']); diff --git a/lib/Folder/FolderManager.php b/lib/Folder/FolderManager.php index 87cad8283..3b4831504 100644 --- a/lib/Folder/FolderManager.php +++ b/lib/Folder/FolderManager.php @@ -23,6 +23,7 @@ use OCP\Files\IRootFolder; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; @@ -32,9 +33,6 @@ use Psr\Log\LoggerInterface; class FolderManager { - public const ENTITY_GROUP = 1; - public const ENTITY_CIRCLE = 2; - public function __construct( private IDBConnection $connection, private IGroupManager $groupManager, @@ -46,9 +44,7 @@ public function __construct( } /** - * @return (array|bool|int|mixed)[][] - * - * @psalm-return array>, id: int, mount_point: mixed, quota: int, size: 0}> + * @return array>, id: int, mount_point: mixed, quota: int, size: 0}> * @throws Exception */ public function getAllFolders(): array { @@ -100,9 +96,7 @@ private function joinQueryWithFileCache(IQueryBuilder $query, int $rootStorageId } /** - * @return (array|bool|int|mixed)[][] - * - * @psalm-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 { @@ -137,9 +131,7 @@ public function getAllFoldersWithSize(int $rootStorageId): array { } /** - * @return (array|bool|int|mixed)[][] - * - * @psalm-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 { @@ -182,9 +174,7 @@ public function getAllFoldersForUserWithSize(int $rootStorageId, IUser $user): a } /** - * @return array[] - * - * @psalm-return array> + * @return array> * @throws Exception */ private function getAllFolderMappings(): array { @@ -210,9 +200,7 @@ private function getAllFolderMappings(): array { } /** - * @return array[] - * - * @psalm-return array> + * @return array> * @throws Exception */ private function getFolderMappings(int $id): array { @@ -294,7 +282,6 @@ public function getFolder(int $id, int $rootStorageId): ?array { /** * Return just the ACL for the folder. * - * @return bool * @throws Exception */ public function getFolderAclEnabled(int $id): bool { @@ -319,9 +306,7 @@ public function getFolderByPath(string $path): int { } /** - * @return int[][] - * - * @psalm-return array>> + * @return array>> * @throws Exception */ private function getAllApplicable(): array { @@ -351,7 +336,6 @@ private function getAllApplicable(): array { /** * @param array $row the row from database - * @param CirclesQueryHelper|null $queryHelper * @param string|null $entityId the type of the entity * * @return array{displayName: string, permissions: int, type: 'circle'|'group'} @@ -393,11 +377,11 @@ private function generateApplicableMapEntry( */ private function getGroups(int $id): array { $groups = $this->getAllApplicable()[$id] ?? []; - $groups = array_map(function ($gid) { + $groups = array_map(function (string $gid): ?IGroup { return $this->groupManager->get($gid); }, array_keys($groups)); - return array_map(function ($group) { + return array_map(function (IGroup $group): array { return [ 'gid' => $group->getGID(), 'displayname' => $group->getDisplayName() @@ -460,7 +444,7 @@ public function searchGroups(int $id, string $search = ''): array { return $groups; } - return array_filter($groups, function ($group) use ($search) { + return array_filter($groups, function (array $group) use ($search): bool { return (stripos($group['gid'], $search) !== false) || (stripos($group['displayname'], $search) !== false); }); } @@ -490,8 +474,6 @@ public function searchUsers(int $id, string $search = '', int $limit = 10, int $ } /** - * @param string $groupId - * @param int $rootStorageId * @return list * @throws Exception */ @@ -530,7 +512,7 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr $result = $query->executeQuery()->fetchAll(); - return array_values(array_map(function ($folder): array { + return array_values(array_map(function (array $folder): array { return [ 'folder_id' => (int)$folder['folder_id'], 'mount_point' => (string)$folder['mount_point'], @@ -544,7 +526,6 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr /** * @param string[] $groupIds - * @param int $rootStorageId * @return array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?CacheEntry}[] * @throws Exception */ @@ -601,8 +582,6 @@ public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): ar } /** - * @param string[] $groupIds - * @param int $rootStorageId * @return array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?CacheEntry}[] * @throws Exception */ @@ -888,8 +867,6 @@ public function setFolderACL(int $folderId, bool $acl): void { } /** - * @param IUser $user - * @param int $rootStorageId * @return list * @throws Exception */ @@ -914,9 +891,6 @@ public function getFoldersForUser(IUser $user, int $rootStorageId = 0): array { } /** - * @param IUser $user - * @param int $folderId - * @return int * @throws Exception */ public function getFolderPermissionsForUser(IUser $user, int $folderId): int { @@ -938,10 +912,6 @@ public function getFolderPermissionsForUser(IUser $user, int $folderId): int { /** * returns if the groupId is in fact the singleId of an existing Circle - * - * @param string $groupId - * - * @return bool */ public function isACircle(string $groupId): bool { $circlesManager = $this->getCirclesManager(); diff --git a/lib/Migration/Version1000000Date20210216085047.php b/lib/Migration/Version1000000Date20210216085047.php index a707512ac..a919c07d9 100644 --- a/lib/Migration/Version1000000Date20210216085047.php +++ b/lib/Migration/Version1000000Date20210216085047.php @@ -12,16 +12,7 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -/** - * Auto-generated migration step: Please modify to your needs! - */ class Version1000000Date20210216085047 extends SimpleMigrationStep { - /** - * @param IOutput $output - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - * @return null|ISchemaWrapper - */ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version102020Date20180806161449.php b/lib/Migration/Version102020Date20180806161449.php index 52a870806..777c7fcf5 100644 --- a/lib/Migration/Version102020Date20180806161449.php +++ b/lib/Migration/Version102020Date20180806161449.php @@ -12,14 +12,7 @@ use OCP\Migration\SimpleMigrationStep; class Version102020Date20180806161449 extends SimpleMigrationStep { - /** - * @param IOutput $output - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - * @return null|ISchemaWrapper - * @since 13.0.0 - */ - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version103000Date20180806161724.php b/lib/Migration/Version103000Date20180806161724.php index c7f0e8d23..d6fc5e7a6 100644 --- a/lib/Migration/Version103000Date20180806161724.php +++ b/lib/Migration/Version103000Date20180806161724.php @@ -13,20 +13,14 @@ use OCP\Migration\SimpleMigrationStep; class Version103000Date20180806161724 extends SimpleMigrationStep { - /** @var IDBConnection */ - private $connection; + private array $applicableData = []; - /** @var array */ - private $applicableData = []; - - public function __construct(IDBConnection $connection) { - $this->connection = $connection; + public function __construct( + private IDBConnection $connection, + ) { } - /** - * @return void - */ - public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); @@ -40,7 +34,7 @@ public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array } } - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); @@ -76,10 +70,7 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op return $schema; } - /** - * @return void - */ - public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) { + public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void { if (count($this->applicableData)) { $query = $this->connection->getQueryBuilder(); $query->insert('group_folders_groups') diff --git a/lib/Migration/Version104000Date20180918132853.php b/lib/Migration/Version104000Date20180918132853.php index 9bc079246..0e3612599 100644 --- a/lib/Migration/Version104000Date20180918132853.php +++ b/lib/Migration/Version104000Date20180918132853.php @@ -12,9 +12,6 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -/** - * Auto-generated migration step: Please modify to your needs! - */ class Version104000Date20180918132853 extends SimpleMigrationStep { public function name(): string { return 'Add group_folders_trash table'; @@ -24,7 +21,7 @@ public function description(): string { return 'Adds table to store trashbin information for group folders'; } - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version16000Date20230821085801.php b/lib/Migration/Version16000Date20230821085801.php index d3803e996..9af0e940c 100644 --- a/lib/Migration/Version16000Date20230821085801.php +++ b/lib/Migration/Version16000Date20230821085801.php @@ -15,16 +15,7 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -/** - * Auto-generated migration step: Please modify to your needs! - */ class Version16000Date20230821085801 extends SimpleMigrationStep { - /** - * @param IOutput $output - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - * @return null|ISchemaWrapper - */ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version19000Date20240903062631.php b/lib/Migration/Version19000Date20240903062631.php index 1fb1b10e4..6bc8d80ca 100644 --- a/lib/Migration/Version19000Date20240903062631.php +++ b/lib/Migration/Version19000Date20240903062631.php @@ -14,16 +14,7 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -/** - * FIXME Auto-generated migration step: Please modify to your needs! - */ class Version19000Date20240903062631 extends SimpleMigrationStep { - /** - * @param IOutput $output - * @param Closure(): ISchemaWrapper $schemaClosure - * @param array $options - * @return null|ISchemaWrapper - */ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version201000Date20190111132839.php b/lib/Migration/Version201000Date20190111132839.php index ceb99ae0c..caaad04c6 100644 --- a/lib/Migration/Version201000Date20190111132839.php +++ b/lib/Migration/Version201000Date20190111132839.php @@ -12,9 +12,6 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -/** - * Auto-generated migration step: Please modify to your needs! - */ class Version201000Date20190111132839 extends SimpleMigrationStep { public function name(): string { return 'Add groupfolder_acl table'; @@ -24,7 +21,7 @@ public function description(): string { return 'Adds table to store ACL information for group folders'; } - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version201000Date20190212150323.php b/lib/Migration/Version201000Date20190212150323.php index 1e5ea0a39..41fdb7e3e 100644 --- a/lib/Migration/Version201000Date20190212150323.php +++ b/lib/Migration/Version201000Date20190212150323.php @@ -12,11 +12,8 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -/** - * Auto-generated migration step: Please modify to your needs! - */ class Version201000Date20190212150323 extends SimpleMigrationStep { - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version300000Date20240905185515.php b/lib/Migration/Version300000Date20240905185515.php index 029a39ea6..e1cb6e42d 100644 --- a/lib/Migration/Version300000Date20240905185515.php +++ b/lib/Migration/Version300000Date20240905185515.php @@ -19,10 +19,6 @@ * Adds the delete_by column to the group_folders_trash table */ class Version300000Date20240905185515 extends SimpleMigrationStep { - - /** - * @param Closure(): ISchemaWrapper $schemaClosure - */ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version401001Date20190715092137.php b/lib/Migration/Version401001Date20190715092137.php index 2a028506f..7d5ee7166 100644 --- a/lib/Migration/Version401001Date20190715092137.php +++ b/lib/Migration/Version401001Date20190715092137.php @@ -12,11 +12,8 @@ use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; -/** - * Auto-generated migration step: Please modify to your needs! - */ class Version401001Date20190715092137 extends SimpleMigrationStep { - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version501000Date20190927102434.php b/lib/Migration/Version501000Date20190927102434.php index e647945eb..b49f6b31a 100644 --- a/lib/Migration/Version501000Date20190927102434.php +++ b/lib/Migration/Version501000Date20190927102434.php @@ -13,13 +13,7 @@ use OCP\Migration\SimpleMigrationStep; class Version501000Date20190927102434 extends SimpleMigrationStep { - /** - * @param IOutput $output - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - * @return null|ISchemaWrapper - */ - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version501000Date20191218182434.php b/lib/Migration/Version501000Date20191218182434.php index 9653b1a73..0fbe3a33b 100644 --- a/lib/Migration/Version501000Date20191218182434.php +++ b/lib/Migration/Version501000Date20191218182434.php @@ -13,13 +13,7 @@ use OCP\Migration\SimpleMigrationStep; class Version501000Date20191218182434 extends SimpleMigrationStep { - /** - * @param IOutput $output - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - * @return null|ISchemaWrapper - */ - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/Version802000Date20201119112624.php b/lib/Migration/Version802000Date20201119112624.php index 36d3c40be..95105b54f 100644 --- a/lib/Migration/Version802000Date20201119112624.php +++ b/lib/Migration/Version802000Date20201119112624.php @@ -13,7 +13,7 @@ use OCP\Migration\SimpleMigrationStep; class Version802000Date20201119112624 extends SimpleMigrationStep { - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); diff --git a/lib/Migration/WrongDefaultQuotaRepairStep.php b/lib/Migration/WrongDefaultQuotaRepairStep.php index 300a4ec82..3d3a367bb 100644 --- a/lib/Migration/WrongDefaultQuotaRepairStep.php +++ b/lib/Migration/WrongDefaultQuotaRepairStep.php @@ -21,12 +21,11 @@ public function __construct( } - public function getName() { + public function getName(): string { return 'Adjust Groupfolders with wrong default quotas'; } /** - * @param IOutput $output * @throws Exception */ public function run(IOutput $output): void { diff --git a/lib/Mount/CacheRootPermissionsMask.php b/lib/Mount/CacheRootPermissionsMask.php index 09738959f..ec281edca 100644 --- a/lib/Mount/CacheRootPermissionsMask.php +++ b/lib/Mount/CacheRootPermissionsMask.php @@ -10,16 +10,17 @@ use OC\Files\Cache\Wrapper\CacheWrapper; use OCP\Files\Cache\ICache; +use OCP\Files\Cache\ICacheEntry; class CacheRootPermissionsMask extends CacheWrapper { - protected int $mask; - - public function __construct(ICache $cache, int $mask) { + public function __construct( + ICache $cache, + private int $mask, + ) { parent::__construct($cache); - $this->mask = $mask; } - protected function formatCacheEntry($entry) { + protected function formatCacheEntry($entry): ICacheEntry|false { $path = $entry['path']; $isRoot = $path === '' || (strpos($path, '__groupfolders') === 0 && count(explode('/', $path)) === 2); if (isset($entry['permissions']) && $isRoot) { diff --git a/lib/Mount/GroupFolderEncryptionJail.php b/lib/Mount/GroupFolderEncryptionJail.php index 93ce0e4e9..295bb6cf3 100644 --- a/lib/Mount/GroupFolderEncryptionJail.php +++ b/lib/Mount/GroupFolderEncryptionJail.php @@ -10,13 +10,20 @@ use OC\Files\Cache\Wrapper\CacheJail; use OC\Files\Storage\Wrapper\Jail; +use OCP\Files\Cache\ICache; +use OCP\Files\Storage\IStorage; /** * Jail with overridden behaviors specific to group folders when encryption is * enabled. */ class GroupFolderEncryptionJail extends Jail { - public function getCache($path = '', $storage = null) { + /** + * @inheritDoc + * @param string $path + * @param ?IStorage $storage + */ + public function getCache($path = '', $storage = null): ICache { if (!$storage) { $storage = $this->getWrapperStorage(); } diff --git a/lib/Mount/GroupFolderStorage.php b/lib/Mount/GroupFolderStorage.php index 707bcd215..b018d0a64 100644 --- a/lib/Mount/GroupFolderStorage.php +++ b/lib/Mount/GroupFolderStorage.php @@ -10,7 +10,10 @@ use OC\Files\ObjectStore\ObjectStoreScanner; use OC\Files\ObjectStore\ObjectStoreStorage; use OC\Files\Storage\Wrapper\Quota; +use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Cache\IScanner; +use OCP\Files\Storage\IStorage; use OCP\IUser; use OCP\IUserSession; @@ -18,9 +21,9 @@ class GroupFolderStorage extends Quota { private int $folderId; private ICacheEntry $rootEntry; private IUserSession $userSession; - private ?IUser $mountOwner = null; + private ?IUser $mountOwner; /** @var RootEntryCache|null */ - public $cache = null; + public $cache; public function __construct($parameters) { parent::__construct($parameters); @@ -47,7 +50,12 @@ public function getOwner($path): string|false { return $this->mountOwner !== null ? $this->mountOwner->getUID() : false; } - public function getCache($path = '', $storage = null) { + /** + * @inheritDoc + * @param string $path + * @param ?IStorage $storage + */ + public function getCache($path = '', $storage = null): ICache { if ($this->cache) { return $this->cache; } @@ -61,7 +69,12 @@ public function getCache($path = '', $storage = null) { return $this->cache; } - public function getScanner($path = '', $storage = null) { + /** + * @inheritDoc + * @param string $path + * @param ?IStorage $storage + */ + public function getScanner($path = '', $storage = null): IScanner { /** @var \OC\Files\Storage\Wrapper\Wrapper $storage */ if (!$storage) { $storage = $this; diff --git a/lib/Mount/GroupMountPoint.php b/lib/Mount/GroupMountPoint.php index ee02ba8b8..aace3a17d 100644 --- a/lib/Mount/GroupMountPoint.php +++ b/lib/Mount/GroupMountPoint.php @@ -8,17 +8,26 @@ use OC\Files\Mount\MountPoint; use OCP\Files\Mount\ISystemMountPoint; +use OCP\Files\Storage\IStorage; +use OCP\Files\Storage\IStorageFactory; class GroupMountPoint extends MountPoint implements ISystemMountPoint { - /** @var int */ - private $folderId; - - public function __construct($folderId, $storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { - $this->folderId = $folderId; + /** + * @param ?IStorage $storage + */ + public function __construct( + private int $folderId, + $storage, + string $mountpoint, + ?array $arguments = null, + ?IStorageFactory $loader = null, + ?array $mountOptions = null, + ?int $mountId = null, + ) { parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, MountProvider::class); } - public function getMountType() { + public function getMountType(): string { return 'group'; } diff --git a/lib/Mount/MountProvider.php b/lib/Mount/MountProvider.php index 55e7c6fac..3536703f9 100644 --- a/lib/Mount/MountProvider.php +++ b/lib/Mount/MountProvider.php @@ -26,66 +26,26 @@ use OCP\Files\Storage\IStorageFactory; use OCP\ICache; use OCP\IDBConnection; -use OCP\IGroupManager; use OCP\IRequest; -use OCP\ISession; use OCP\IUser; use OCP\IUserSession; class MountProvider implements IMountProvider { - /** @var IGroupManager */ - private $groupProvider; - - /** @var callable */ - private $rootProvider; - - /** @var Folder|null */ - private $root = null; - - /** @var FolderManager */ - private $folderManager; - - private $aclManagerFactory; - - private $userSession; - - private $request; - - private $session; - - private $mountProviderCollection; - private $connection; - private ICache $cache; + private ?Folder $root = null; private ?int $rootStorageId = null; - private bool $allowRootShare; - private bool $enableEncryption; public function __construct( - IGroupManager $groupProvider, - FolderManager $folderManager, - callable $rootProvider, - ACLManagerFactory $aclManagerFactory, - IUserSession $userSession, - IRequest $request, - ISession $session, - IMountProviderCollection $mountProviderCollection, - IDBConnection $connection, - ICache $cache, - bool $allowRootShare, - bool $enableEncryption, + private FolderManager $folderManager, + private \Closure $rootProvider, + private ACLManagerFactory $aclManagerFactory, + private IUserSession $userSession, + private IRequest $request, + private IMountProviderCollection $mountProviderCollection, + private IDBConnection $connection, + private ICache $cache, + private bool $allowRootShare, + private bool $enableEncryption, ) { - $this->groupProvider = $groupProvider; - $this->folderManager = $folderManager; - $this->rootProvider = $rootProvider; - $this->aclManagerFactory = $aclManagerFactory; - $this->userSession = $userSession; - $this->request = $request; - $this->session = $session; - $this->mountProviderCollection = $mountProviderCollection; - $this->connection = $connection; - $this->cache = $cache; - $this->allowRootShare = $allowRootShare; - $this->enableEncryption = $enableEncryption; } private function getRootStorageId(): int { @@ -110,24 +70,24 @@ public function getFoldersForUser(IUser $user): array { return $this->folderManager->getFoldersForUser($user, $this->getRootStorageId()); } - public function getMountsForUser(IUser $user, IStorageFactory $loader) { + public function getMountsForUser(IUser $user, IStorageFactory $loader): array { $folders = $this->getFoldersForUser($user); - $mountPoints = array_map(function (array $folder) { + $mountPoints = array_map(function (array $folder): string { return 'files/' . $folder['mount_point']; }, $folders); $conflicts = $this->findConflictsForUser($user, $mountPoints); - $foldersWithAcl = array_filter($folders, function (array $folder) { + $foldersWithAcl = array_filter($folders, function (array $folder): bool { return $folder['acl']; }); - $aclRootPaths = array_map(function (array $folder) { + $aclRootPaths = array_map(function (array $folder): string { return $this->getJailPath($folder['folder_id']); }, $foldersWithAcl); $aclManager = $this->aclManagerFactory->getACLManager($user, $this->getRootStorageId()); $rootRules = $aclManager->getRelevantRulesForPath($aclRootPaths); - return array_values(array_filter(array_map(function ($folder) use ($user, $loader, $conflicts, $aclManager, $rootRules) { + return array_values(array_filter(array_map(function (array $folder) use ($user, $loader, $conflicts, $aclManager, $rootRules): ?IMountPoint { // check for existing files in the user home and rename them if needed $originalFolderName = $folder['mount_point']; if (in_array($originalFolderName, $conflicts)) { diff --git a/lib/Mount/RootEntryCache.php b/lib/Mount/RootEntryCache.php index b97940055..9a83d6aba 100644 --- a/lib/Mount/RootEntryCache.php +++ b/lib/Mount/RootEntryCache.php @@ -9,18 +9,18 @@ namespace OCA\GroupFolders\Mount; use OC\Files\Cache\Wrapper\CacheWrapper; +use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; class RootEntryCache extends CacheWrapper { - /** @var ICacheEntry|null */ - private $rootEntry; - - public function __construct($cache, ?ICacheEntry $rootEntry = null) { + public function __construct( + ICache $cache, + private ?ICacheEntry $rootEntry = null, + ) { parent::__construct($cache); - $this->rootEntry = $rootEntry; } - public function get($file) { + public function get($file): ICacheEntry|false { if ($file === '' && $this->rootEntry) { return $this->rootEntry; } @@ -28,7 +28,7 @@ public function get($file) { return parent::get($file); } - public function getId($file) { + public function getId($file): int { if ($file === '' && $this->rootEntry) { return $this->rootEntry->getId(); } @@ -36,12 +36,12 @@ public function getId($file) { return parent::getId($file); } - public function update($id, array $data) { + public function update($id, array $data): void { $this->rootEntry = null; parent::update($id, $data); } - public function insert($file, array $data) { + public function insert($file, array $data): int { $this->rootEntry = null; return parent::insert($file, $data); } diff --git a/lib/Mount/RootPermissionsMask.php b/lib/Mount/RootPermissionsMask.php index f340ebc0c..2ca862352 100644 --- a/lib/Mount/RootPermissionsMask.php +++ b/lib/Mount/RootPermissionsMask.php @@ -10,15 +10,17 @@ use OC\Files\Storage\Wrapper\Wrapper; use OCP\Constants; +use OCP\Files\Cache\ICache; +use OCP\Files\Storage\IStorage; /** * Permissions mask that only masks the root of the storage */ class RootPermissionsMask extends Wrapper { /** - * @var int the permissions bits we want to keep + * the permissions bits we want to keep */ - private $mask; + private int $mask; /** * @param array $arguments ['storage' => $storage, 'mask' => $mask] @@ -31,11 +33,11 @@ public function __construct($arguments) { $this->mask = $arguments['mask']; } - private function checkMask($permissions) { + private function checkMask(int $permissions): bool { return ($this->mask & $permissions) === $permissions; } - public function isUpdatable($path) { + public function isUpdatable($path): bool { if ($path === '') { return $this->checkMask(Constants::PERMISSION_UPDATE) and parent::isUpdatable($path); } else { @@ -43,7 +45,7 @@ public function isUpdatable($path) { } } - public function isCreatable($path) { + public function isCreatable($path): bool { if ($path === '') { return $this->checkMask(Constants::PERMISSION_CREATE) and parent::isCreatable($path); } else { @@ -51,7 +53,7 @@ public function isCreatable($path) { } } - public function isDeletable($path) { + public function isDeletable($path): bool { if ($path === '') { return $this->checkMask(Constants::PERMISSION_DELETE) and parent::isDeletable($path); } else { @@ -59,7 +61,7 @@ public function isDeletable($path) { } } - public function isSharable($path) { + public function isSharable($path): bool { if ($path === '') { return $this->checkMask(Constants::PERMISSION_SHARE) and parent::isSharable($path); } else { @@ -67,7 +69,7 @@ public function isSharable($path) { } } - public function getPermissions($path) { + public function getPermissions($path): int { if ($path === '') { return $this->storage->getPermissions($path) & $this->mask; } else { @@ -75,7 +77,7 @@ public function getPermissions($path) { } } - public function getMetaData($path) { + public function getMetaData($path): ?array { $data = parent::getMetaData($path); if ($data && $path === '' && isset($data['permissions'])) { @@ -86,7 +88,11 @@ public function getMetaData($path) { return $data; } - public function getCache($path = '', $storage = null) { + /** + * @param string $path + * @param ?IStorage $storage + */ + public function getCache($path = '', $storage = null): ICache { if (!$storage) { $storage = $this; } diff --git a/lib/Service/ApplicationService.php b/lib/Service/ApplicationService.php index d552a138c..4e3492e04 100644 --- a/lib/Service/ApplicationService.php +++ b/lib/Service/ApplicationService.php @@ -11,10 +11,9 @@ use OCP\App\IAppManager; class ApplicationService { - private IAppManager $appManager; - - public function __construct(IAppManager $appManager) { - $this->appManager = $appManager; + public function __construct( + private IAppManager $appManager, + ) { } /** diff --git a/lib/Service/DelegationService.php b/lib/Service/DelegationService.php index cf562834c..2c7ace146 100644 --- a/lib/Service/DelegationService.php +++ b/lib/Service/DelegationService.php @@ -25,39 +25,23 @@ class DelegationService { */ private const CLASS_API_ACCESS = DelegationController::class; - private AuthorizedGroupMapper $groupAuthorizationMapper; - private IGroupManager $groupManager; - private IUserSession $userSession; - public function __construct( - AuthorizedGroupMapper $groupAuthorizationMapper, - IGroupManager $groupManager, - IUserSession $userSession, + private AuthorizedGroupMapper $groupAuthorizationMapper, + private IGroupManager $groupManager, + private IUserSession $userSession, ) { - $this->groupAuthorizationMapper = $groupAuthorizationMapper; - $this->groupManager = $groupManager; - $this->userSession = $userSession; } - /** - * @return bool true is admin of nextcloud otherwise false. - */ public function isAdminNextcloud(): bool { return $this->groupManager->isAdmin($this->userSession->getUser()->getUID()); } - /** - * @return bool true if the user is a delegated admin - */ public function isDelegatedAdmin(): bool { return $this->getAccessLevel([ self::CLASS_NAME_ADMIN_DELEGATION, ]); } - /** - * @return bool true if the user has api access - */ public function hasApiAccess(): bool { if ($this->isAdminNextcloud()) { return true; @@ -69,9 +53,6 @@ public function hasApiAccess(): bool { ]); } - /** - * @return bool true if the user has api access - */ public function hasOnlyApiAccess(): bool { return $this->getAccessLevel([ self::CLASS_API_ACCESS, diff --git a/lib/Service/FoldersFilter.php b/lib/Service/FoldersFilter.php index 67b60f508..584942b65 100644 --- a/lib/Service/FoldersFilter.php +++ b/lib/Service/FoldersFilter.php @@ -11,21 +11,19 @@ use OCP\IUserSession; class FoldersFilter { - private IUserSession $userSession; - private IGroupManager $groupManager; - - public function __construct(IUserSession $userSession, IGroupManager $groupManager) { - $this->userSession = $userSession; - $this->groupManager = $groupManager; + public function __construct( + private IUserSession $userSession, + private IGroupManager $groupManager, + ) { } /** * @param array $folders List of all folders - * @return array $folders List of folders that the api user can access + * @return array List of folders that the api user can access */ public function getForApiUser(array $folders): array { $user = $this->userSession->getUser(); - $folders = array_filter($folders, function (array $folder) use ($user) { + $folders = array_filter($folders, function (array $folder) use ($user): bool { foreach ($folder['manage'] as $manager) { if ($manager['type'] === 'group') { if ($this->groupManager->isInGroup($user->getUid(), $manager['id'])) { diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 213352be2..9658cd96a 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -35,7 +35,7 @@ public function getForm(): TemplateResponse { 'isAdminNextcloud', $this->delegationService->isAdminNextcloud() ); - + $this->initialState->provideInitialState( 'isCirclesEnabled', $this->appManager->isEnabledForUser('circles') @@ -53,13 +53,6 @@ public function getSection(): string { return Application::APP_ID; } - /** - * @return int whether the form should be rather on the top or bottom of - * the admin section. The forms are arranged in ascending order of the - * priority values. It is required to return a value between 0 and 100. - * - * E.g.: 70 - */ public function getPriority(): int { return 90; } diff --git a/lib/Settings/Section.php b/lib/Settings/Section.php index a64a52198..60f3ed3e9 100644 --- a/lib/Settings/Section.php +++ b/lib/Settings/Section.php @@ -18,42 +18,19 @@ public function __construct( ) { } - /** - * @return string The ID of the section. It is supposed to be a lower case string, e.g. 'ldap' - * - * @psalm-return 'groupfolders' - */ - public function getID() { + public function getID(): string { return Application::APP_ID; } - /** - * Returns the translated name as it should be displayed, e.g. 'LDAP / AD - * integration'. Use the L10N service to translate it. - * - * @return string - */ - public function getName() { + public function getName(): string { return $this->l->t('Group folders'); } - /** - * @return int whether the form should be rather on the top or bottom of - * the settings navigation. The sections are arranged in ascending order of - * the priority values. It is required to return a value between 0 and 99. - * - * E.g.: 70 - */ - public function getPriority() { + public function getPriority(): int { return 90; } - /** - * * {@inheritdoc} - * - * @return string - */ - public function getIcon() { + public function getIcon(): string { return $this->url->imagePath('groupfolders', 'app-dark.svg'); } } diff --git a/lib/Trash/GroupTrashItem.php b/lib/Trash/GroupTrashItem.php index a026d27d7..3e24f8375 100644 --- a/lib/Trash/GroupTrashItem.php +++ b/lib/Trash/GroupTrashItem.php @@ -10,11 +10,10 @@ use OCA\Files_Trashbin\Trash\ITrashBackend; use OCA\Files_Trashbin\Trash\TrashItem; use OCP\Files\FileInfo; +use OCP\Files\Storage\IStorage; use OCP\IUser; class GroupTrashItem extends TrashItem { - private string $mountPoint; - public function __construct( ITrashBackend $backend, string $originalLocation, @@ -22,11 +21,10 @@ public function __construct( string $trashPath, FileInfo $fileInfo, IUser $user, - string $mountPoint, - private ?IUser $deletedBy, + private string $mountPoint, + ?IUser $deletedBy, ) { parent::__construct($backend, $originalLocation, $deletedTime, $trashPath, $fileInfo, $user, $deletedBy); - $this->mountPoint = $mountPoint; } public function isRootItem(): bool { @@ -41,7 +39,7 @@ public function getTitle(): string { return $this->getGroupFolderMountPoint() . '/' . $this->getOriginalLocation(); } - public function getStorage() { + public function getStorage(): IStorage { // get the unjailed storage, since the trash item is outside the jail // (the internal path is also unjailed) $groupFolderStorage = parent::getStorage(); @@ -53,12 +51,12 @@ public function getStorage() { return $groupFolderStorage; } - public function getMtime() { + public function getMtime(): int { // trashbin is currently (incorrectly) assuming these to be the same return $this->getDeletedTime(); } - public function getInternalPath() { + public function getInternalPath(): string { // trashbin expects the path without the deletion timestamp $path = parent::getInternalPath(); diff --git a/lib/Trash/TrashBackend.php b/lib/Trash/TrashBackend.php index 750f7661d..478a548d4 100644 --- a/lib/Trash/TrashBackend.php +++ b/lib/Trash/TrashBackend.php @@ -29,8 +29,7 @@ use Psr\Log\LoggerInterface; class TrashBackend implements ITrashBackend { - /** @var ?VersionsBackend */ - private $versionsBackend = null; + private ?VersionsBackend $versionsBackend = null; public function __construct( private FolderManager $folderManager, @@ -74,7 +73,7 @@ public function listTrashFolder(ITrashItem $folder): array { $content = $folderNode->getDirectoryListing(); $this->aclManagerFactory->getACLManager($user)->preloadRulesForFolder($folder->getPath()); - return array_values(array_filter(array_map(function (Node $node) use ($folder, $user) { + return array_values(array_filter(array_map(function (Node $node) use ($folder, $user): ?GroupTrashItem { if (!$this->userHasAccessToPath($user, $folder->getPath() . '/' . $node->getName())) { return null; } @@ -93,10 +92,9 @@ public function listTrashFolder(ITrashItem $folder): array { } /** - * @return void * @throws NotPermittedException */ - public function restoreItem(ITrashItem $item) { + public function restoreItem(ITrashItem $item): void { if (!($item instanceof GroupTrashItem)) { throw new \LogicException('Trying to restore normal trash item in group folder trash backend'); } @@ -134,7 +132,7 @@ public function restoreItem(ITrashItem $item) { $info = pathinfo($originalLocation); $i = 1; - $gen = function ($info, int $i): string { + $gen = function (array $info, int $i): string { $target = $info['dirname']; if ($target === '.') { $target = ''; @@ -171,11 +169,10 @@ public function restoreItem(ITrashItem $item) { } /** - * @return void * @throws \LogicException * @throws \Exception */ - public function removeItem(ITrashItem $item) { + public function removeItem(ITrashItem $item): void { if (!($item instanceof GroupTrashItem)) { throw new \LogicException('Trying to remove normal trash item in group folder trash backend'); } @@ -309,7 +306,6 @@ private function getTrashFolder(int $folderId): Folder { } /** - * @param IUser $user * @param array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}[] $folders * @return list */ @@ -499,9 +495,6 @@ public function expire(Expiration $expiration): array { /** * Cleanup trashbin of of groupfolders that have been deleted - * - * @param array $existingFolders - * @return void */ private function cleanupDeletedFoldersTrash(array $existingFolders): void { $trashRoot = $this->getTrashRoot(); diff --git a/lib/Trash/TrashManager.php b/lib/Trash/TrashManager.php index 8aa57018b..a88f4e225 100644 --- a/lib/Trash/TrashManager.php +++ b/lib/Trash/TrashManager.php @@ -13,12 +13,10 @@ class TrashManager { public function __construct( private IDBConnection $connection, ) { - $this->connection = $connection; } /** * @param int[] $folderIds - * @return array */ public function listTrashForFolders(array $folderIds): array { $query = $this->connection->getQueryBuilder(); diff --git a/lib/Versions/ExpireManager.php b/lib/Versions/ExpireManager.php index 74d90056c..02e0328e8 100644 --- a/lib/Versions/ExpireManager.php +++ b/lib/Versions/ExpireManager.php @@ -31,17 +31,14 @@ class ExpireManager { 6 => ['intervalEndsAfter' => -1, 'step' => 604800], ]; - /** @var Expiration */ - private $expiration; - - public function __construct(Expiration $expiration) { - $this->expiration = $expiration; + public function __construct( + private Expiration $expiration, + ) { } /** * Get list of files we want to expire * - * @param integer $time * @param IVersion[] $versions * @return IVersion[] */ @@ -53,7 +50,7 @@ protected function getAutoExpireList(int $time, array $versions): array { $toDelete = []; // versions we want to delete // ensure the versions are sorted newest first - usort($versions, function (IVersion $a, IVersion $b) { + usort($versions, function (IVersion $a, IVersion $b): int { return $b->getTimestamp() <=> $a->getTimestamp(); }); @@ -100,8 +97,6 @@ protected function getAutoExpireList(int $time, array $versions): array { /** * @param IVersion[] $versions - * @param int $time - * @param boolean $quotaExceeded * @return IVersion[] */ public function getExpiredVersion(array $versions, int $time, bool $quotaExceeded): array { @@ -111,12 +106,12 @@ public function getExpiredVersion(array $versions, int $time, bool $quotaExceede $autoExpire = []; } - $versionsLeft = array_udiff($versions, $autoExpire, function (IVersion $a, IVersion $b) { + $versionsLeft = array_udiff($versions, $autoExpire, function (IVersion $a, IVersion $b): int { return ($a->getRevisionId() <=> $b->getRevisionId()) * ($a->getSourceFile()->getId() <=> $b->getSourceFile()->getId()); }); - $expired = array_filter($versionsLeft, function (IVersion $version) use ($quotaExceeded) { + $expired = array_filter($versionsLeft, function (IVersion $version) use ($quotaExceeded): bool { // Do not expire current version. if ($version->getTimestamp() === $version->getSourceFile()->getMtime()) { return false; diff --git a/lib/Versions/GroupVersionsExpireManager.php b/lib/Versions/GroupVersionsExpireManager.php index 11f749cc6..730b939f2 100644 --- a/lib/Versions/GroupVersionsExpireManager.php +++ b/lib/Versions/GroupVersionsExpireManager.php @@ -18,24 +18,13 @@ use OCP\IUser; class GroupVersionsExpireManager extends BasicEmitter { - private $folderManager; - private $expireManager; - private $versionsBackend; - private $timeFactory; - private $dispatcher; - public function __construct( - FolderManager $folderManager, - ExpireManager $expireManager, - VersionsBackend $versionsBackend, - ITimeFactory $timeFactory, - IEventDispatcher $dispatcher, + private FolderManager $folderManager, + private ExpireManager $expireManager, + private VersionsBackend $versionsBackend, + private ITimeFactory $timeFactory, + private IEventDispatcher $dispatcher, ) { - $this->folderManager = $folderManager; - $this->expireManager = $expireManager; - $this->versionsBackend = $versionsBackend; - $this->timeFactory = $timeFactory; - $this->dispatcher = $dispatcher; } public function expireAll(): void { diff --git a/lib/Versions/GroupVersionsMapper.php b/lib/Versions/GroupVersionsMapper.php index d9329ad26..101f67754 100644 --- a/lib/Versions/GroupVersionsMapper.php +++ b/lib/Versions/GroupVersionsMapper.php @@ -33,9 +33,6 @@ public function findAllVersionsForFileId(int $fileId): array { return $this->findEntities($qb); } - /** - * @return GroupVersionEntity - */ public function findCurrentVersionForFileId(int $fileId): GroupVersionEntity { $qb = $this->db->getQueryBuilder(); diff --git a/lib/Versions/VersionsBackend.php b/lib/Versions/VersionsBackend.php index b54c436af..d2737dccd 100644 --- a/lib/Versions/VersionsBackend.php +++ b/lib/Versions/VersionsBackend.php @@ -146,7 +146,7 @@ private function getVersionsForFileFromDB(FileInfo $fileInfo, IUser $user): arra $versionEntities = $this->groupVersionsMapper->findAllVersionsForFileId($fileInfo->getId()); $mappedVersions = array_map( - function (GroupVersionEntity $versionEntity) use ($versionsFolder, $mountPoint, $fileInfo, $user, $folderId, $groupFolder) { + function (GroupVersionEntity $versionEntity) use ($versionsFolder, $mountPoint, $fileInfo, $user, $folderId, $groupFolder): ?GroupVersion { if ($fileInfo->getMtime() === $versionEntity->getTimestamp()) { if ($fileInfo instanceof File) { $versionFile = $fileInfo; @@ -187,10 +187,7 @@ function (GroupVersionEntity $versionEntity) use ($versionsFolder, $mountPoint, return array_filter($mappedVersions); } - /** - * @return void - */ - public function createVersion(IUser $user, FileInfo $file) { + public function createVersion(IUser $user, FileInfo $file): void { $versionsFolder = $this->getVersionFolderForFile($file); $versionMount = $versionsFolder->getMountPoint(); @@ -247,9 +244,9 @@ public function getVersionFile(IUser $user, FileInfo $sourceFile, $revision): Fi /** * @param array{id: int, mount_point: string, groups: array|mixed, quota: mixed, size: int, acl: bool} $folder - * @return (FileInfo|null)[] [$fileId => FileInfo|null] + * @return array */ - public function getAllVersionedFiles(array $folder) { + public function getAllVersionedFiles(array $folder): array { $versionsFolder = $this->getVersionsFolder($folder['id']); $mount = $this->mountProvider->getMount($folder['id'], '/dummyuser/files/' . $folder['mount_point'], Constants::PERMISSION_ALL, $folder['quota']); if ($mount === null) { diff --git a/psalm.xml b/psalm.xml index c580e7963..e388246ff 100644 --- a/psalm.xml +++ b/psalm.xml @@ -119,5 +119,13 @@ + + + + + + + +