From ce21956150a0e2c192d8fd460ca4d06b09f64ace 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 | 29 +++---- lib/ACL/ACLManager.php | 20 ++--- lib/ACL/ACLManagerFactory.php | 5 +- lib/ACL/ACLStorageWrapper.php | 81 ++++++++++--------- lib/ACL/Rule.php | 43 +++------- lib/ACL/RuleManager.php | 48 ++++------- lib/ACL/UserMapping/IUserMapping.php | 2 +- lib/ACL/UserMapping/IUserMappingManager.php | 6 -- lib/ACL/UserMapping/UserMapping.php | 11 +-- lib/ACL/UserMapping/UserMappingManager.php | 9 +-- lib/AppInfo/Application.php | 17 ++-- lib/AppInfo/Capabilities.php | 13 ++- lib/AuthorizedAdminSettingMiddleware.php | 29 ++----- lib/BackgroundJob/ExpireGroupPlaceholder.php | 2 +- lib/BackgroundJob/ExpireGroupTrash.php | 18 ++--- lib/BackgroundJob/ExpireGroupVersions.php | 7 +- lib/Command/ACL.php | 27 +++---- lib/Command/Create.php | 9 +-- lib/Command/Delete.php | 4 +- lib/Command/ExpireGroup/ExpireGroupTrash.php | 9 +-- .../ExpireGroup/ExpireGroupVersions.php | 11 +-- .../ExpireGroup/ExpireGroupVersionsTrash.php | 9 +-- .../ExpireGroupVersionsPlaceholder.php | 8 +- lib/Command/FolderCommand.php | 12 ++- lib/Command/Group.php | 8 +- lib/Command/ListCommand.php | 27 +++---- lib/Command/Quota.php | 4 +- lib/Command/Scan.php | 12 +-- lib/Command/Trashbin/Cleanup.php | 7 +- lib/Controller/FolderController.php | 40 +++------ lib/DAV/ACLPlugin.php | 30 +++---- lib/DAV/GroupFolderNode.php | 5 +- lib/DAV/GroupFoldersHome.php | 23 ++---- lib/DAV/RootCollection.php | 2 - lib/Folder/FolderManager.php | 52 +++--------- .../Version1000000Date20210216085047.php | 9 --- .../Version102020Date20180806161449.php | 9 +-- .../Version103000Date20180806161724.php | 21 ++--- .../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 | 8 +- lib/Mount/GroupFolderEncryptionJail.php | 9 ++- lib/Mount/GroupFolderStorage.php | 21 ++++- lib/Mount/GroupMountPoint.php | 21 +++-- lib/Mount/MountProvider.php | 72 ++++------------- lib/Mount/RootEntryCache.php | 15 ++-- lib/Mount/RootPermissionsMask.php | 26 +++--- lib/Service/ApplicationService.php | 5 +- lib/Service/DelegationService.php | 25 +----- lib/Service/FoldersFilter.php | 11 +-- lib/Settings/Admin.php | 9 +-- lib/Settings/Section.php | 31 +------ lib/Trash/GroupTrashItem.php | 12 ++- lib/Trash/TrashBackend.php | 19 ++--- lib/Trash/TrashManager.php | 2 - lib/Versions/ExpireManager.php | 15 +--- lib/Versions/GroupVersionsExpireManager.php | 21 ++--- lib/Versions/GroupVersionsMapper.php | 3 - lib/Versions/VersionsBackend.php | 11 +-- psalm.xml | 8 ++ 69 files changed, 361 insertions(+), 724 deletions(-) diff --git a/lib/ACL/ACLCacheWrapper.php b/lib/ACL/ACLCacheWrapper.php index 62c3da8bb..9e9806311 100644 --- a/lib/ACL/ACLCacheWrapper.php +++ b/lib/ACL/ACLCacheWrapper.php @@ -15,10 +15,11 @@ 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 { @@ -35,13 +36,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); @@ -52,27 +47,27 @@ 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); return array_filter(array_map([$this, 'formatCacheEntry'], $results)); @@ -80,10 +75,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); return $this->aclManager->getRelevantRulesForPath($paths, false); diff --git a/lib/ACL/ACLManager.php b/lib/ACL/ACLManager.php index 9de0b626c..78e96a20f 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 { @@ -83,7 +80,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 { @@ -144,9 +140,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, '/'); @@ -157,7 +151,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 @@ -207,9 +200,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 b80948a85..0bae307dc 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 @@ -36,37 +37,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 @@ -108,29 +109,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); @@ -139,15 +140,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; } @@ -167,13 +165,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; } @@ -181,7 +177,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'])) { @@ -191,31 +187,36 @@ 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; } 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; } return parent::stat($path); } - public function filetype($path) { + public function filetype($path): string|bool { if (!$this->checkPermissions($path, Constants::PERMISSION_READ)) { return false; } @@ -229,47 +230,47 @@ 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; } 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; } 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; } 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; } 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; } 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 068fd409e..a06a185e4 100644 --- a/lib/ACL/Rule.php +++ b/lib/ACL/Rule.php @@ -32,19 +32,14 @@ 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 +63,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; @@ -84,10 +76,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,7 +90,7 @@ public function xmlSerialize(Writer $writer) { } #[\ReturnTypeWillChange] - public function jsonSerialize() { + public function jsonSerialize(): array { return [ 'mapping' => [ 'type' => $this->getUserMapping()->getType(), @@ -128,17 +117,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); @@ -154,9 +140,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); @@ -165,8 +148,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 f8e53dba4..8dfb26525 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())) @@ -76,10 +73,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); @@ -96,7 +91,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())) @@ -115,10 +110,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); @@ -139,7 +131,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())) @@ -176,12 +168,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(); @@ -210,9 +201,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(); @@ -231,10 +220,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); @@ -248,7 +234,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..bab4f213b 100644 --- a/lib/ACL/UserMapping/UserMapping.php +++ b/lib/ACL/UserMapping/UserMapping.php @@ -9,18 +9,15 @@ 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..b00978e3a 100644 --- a/lib/ACL/UserMapping/UserMappingManager.php +++ b/lib/ACL/UserMapping/UserMappingManager.php @@ -14,16 +14,11 @@ 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 89e6d64bc..5c3f6a500 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; @@ -85,9 +84,11 @@ public function register(IRegistrationContext $context): void { $context->registerService('GroupAppFolder', function (ContainerInterface $c): Folder { /** @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'); } @@ -105,13 +106,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'), @@ -183,7 +182,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), @@ -197,7 +196,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), @@ -232,7 +231,7 @@ public function boot(IBootContext $context): void { $context->injectFn(function (IMountProviderCollection $mountProviderCollection, CacheListener $cacheListener, Group\Manager $groupManager): void { $mountProviderCollection->registerProvider($this->getMountProvider()); - $groupManager->listen('\OC\Group', 'postDelete', function (IGroup $group) { + $groupManager->listen('\OC\Group', 'postDelete', function (IGroup $group): void { $this->getFolderManager()->deleteGroup($group->getGID()); }); $cacheListener->listen(); diff --git a/lib/AppInfo/Capabilities.php b/lib/AppInfo/Capabilities.php index 3c1b942f4..ec60f41e9 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 abff09e6a..7ee8f10ab 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 433f3fd60..8989d10a5 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, - ITimeFactory $timeFactory + 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 a36b23545..74db02568 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; @@ -184,7 +177,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)); @@ -194,12 +187,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); @@ -209,7 +202,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 414c93a46..3cd5e52bb 100644 --- a/lib/Command/Create.php +++ b/lib/Command/Create.php @@ -15,14 +15,11 @@ 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 +27,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); return 0; diff --git a/lib/Command/Delete.php b/lib/Command/Delete.php index 2a9026bde..2880d034a 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 cc1c6dfb3..1c5dfd613 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 e8404c7ca..78dc84823 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 { @@ -34,16 +31,16 @@ protected function configure(): void { } protected function execute(InputInterface $input, OutputInterface $output): int { - $this->expireManager->listen(GroupVersionsExpireManager::class, 'enterFolder', function (array $folder) use ($output) { + $this->expireManager->listen(GroupVersionsExpireManager::class, 'enterFolder', function (array $folder) use ($output): void { $output->writeln("Expiring version in '{$folder['mount_point']}'"); }); - $this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteVersion', function (IVersion $version) use ($output) { + $this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteVersion', function (IVersion $version) use ($output): void { $id = $version->getRevisionId(); $file = $version->getSourceFileName(); $output->writeln("Expiring version $id for '$file'"); }); - $this->expireManager->listen(GroupVersionsExpireManager::class, 'deleteFile', function ($id) use ($output) { + $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 776dc27f0..67fd8da2d 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 c3158445b..e72c52b99 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( + private FolderManager $folderManager, + private IRootFolder $rootFolder, + private 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 f8f5198ae..fe5c3aee1 100644 --- a/lib/Command/Group.php +++ b/lib/Command/Group.php @@ -25,14 +25,12 @@ 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(private 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 +42,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 cbe083292..5b019b069 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 = []; @@ -68,7 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { } else { $folders = $this->folderManager->getAllFoldersWithSize($rootStorageId); } - usort($folders, function ($a, $b) { + usort($folders, function (array $a, array $b): int { return $a['id'] - $b['id']; }); @@ -85,7 +82,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']); } @@ -103,7 +100,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); @@ -118,7 +115,7 @@ private function permissionsToString(int $permissions): string { if ($permissions === 0) { 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 9dcffa3a9..6f9384706 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 9c17321bf..74fabd997 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) { @@ -92,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { return -1; } - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFile', function ($path) use ($output, &$statsRow) { + $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 @@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { } }); - $scanner->listen('\OC\Files\Cache\Scanner', 'scanFolder', function ($path) use ($output, &$statsRow) { + $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 @@ -125,11 +125,11 @@ 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 7abccee08..69015ff42 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 669ceadc2..d1c0a7307 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']); return $folder; @@ -285,11 +270,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 0ff64151f..0337a9a46 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, @@ -92,7 +93,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]); @@ -102,9 +103,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())) { @@ -119,7 +120,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(); @@ -135,7 +135,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(), @@ -145,16 +145,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()); }); } @@ -171,7 +171,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; @@ -184,7 +184,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(), @@ -193,7 +193,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)) { @@ -212,14 +212,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..12d28063b 100644 --- a/lib/DAV/GroupFolderNode.php +++ b/lib/DAV/GroupFolderNode.php @@ -13,11 +13,8 @@ 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 2e3c39559..af40e9004 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 { @@ -72,7 +62,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'; @@ -80,7 +69,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); @@ -90,7 +79,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 5f52e246e..dd97801c4 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 019184de6..a85cdc830 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 { @@ -290,7 +278,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 { @@ -314,9 +301,7 @@ public function getFolderByPath(string $path): int { } /** - * @return int[][] - * - * @psalm-return array>> + * @return array>> * @throws Exception */ private function getAllApplicable(): array { @@ -346,7 +331,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'} @@ -387,10 +371,10 @@ 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() @@ -451,7 +435,7 @@ public function searchGroups(int $id, string $search = ''): array { if ($search === '') { 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); }); } @@ -480,8 +464,6 @@ public function searchUsers(int $id, string $search = '', int $limit = 10, int $ } /** - * @param string $groupId - * @param int $rootStorageId * @return list * @throws Exception */ @@ -519,7 +501,7 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr $this->joinQueryWithFileCache($query, $rootStorageId); $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'], @@ -533,7 +515,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 */ @@ -590,8 +571,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 */ @@ -876,8 +855,6 @@ public function setFolderACL(int $folderId, bool $acl): void { } /** - * @param IUser $user - * @param int $rootStorageId * @return list * @throws Exception */ @@ -902,9 +879,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 { @@ -926,10 +900,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 00d473071..ee669fd10 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 9aef4de68..aa57d409f 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..2261a548c 100644 --- a/lib/Migration/Version103000Date20180806161724.php +++ b/lib/Migration/Version103000Date20180806161724.php @@ -13,20 +13,12 @@ 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 +32,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 +68,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 e260f8902..725a05db8 100644 --- a/lib/Mount/CacheRootPermissionsMask.php +++ b/lib/Mount/CacheRootPermissionsMask.php @@ -10,16 +10,14 @@ 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 7f9ce9e1a..3f8d5d90a 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 7bc54835e..5f9dd6644 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); @@ -46,7 +49,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; } @@ -58,7 +66,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 dff103d83..85f28c2f0 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 { @@ -109,24 +69,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 67bd06844..3599a7b45 100644 --- a/lib/Mount/RootEntryCache.php +++ b/lib/Mount/RootEntryCache.php @@ -9,37 +9,34 @@ 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; } return parent::get($file); } - public function getId($file) { + public function getId($file): int { if ($file === '' && $this->rootEntry) { return $this->rootEntry->getId(); } 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 3f1b01089..68eac6ca8 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'])) { @@ -85,7 +87,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..b40d2785d 100644 --- a/lib/Service/ApplicationService.php +++ b/lib/Service/ApplicationService.php @@ -11,10 +11,7 @@ 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 ac3d6fca4..d0e7681ec 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; @@ -68,9 +52,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 dfcf50a78..01d627edd 100644 --- a/lib/Service/FoldersFilter.php +++ b/lib/Service/FoldersFilter.php @@ -11,21 +11,16 @@ 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 5b80c1438..4403af186 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 126a6aa66..d05cb696a 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 7371f0487..406ad695e 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 string $mountPoint, private ?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(); @@ -52,12 +50,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(); return rtrim($path, '.d' . $this->getDeletedTime()); diff --git a/lib/Trash/TrashBackend.php b/lib/Trash/TrashBackend.php index 961ca6046..b7c3f6962 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, @@ -71,7 +70,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; } @@ -89,10 +88,9 @@ public function listTrashFolder(ITrashItem $folder): array { } /** - * @return void - * @throw NotPermittedException + * @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'); } @@ -126,7 +124,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 = ''; @@ -163,11 +161,10 @@ public function restoreItem(ITrashItem $item) { } /** - * @return void * @throw \LogicException * @throw \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'); } @@ -289,7 +286,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 */ @@ -469,9 +465,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 b44834387..e648f1e2f 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 eba57447b..39fe977dd 100644 --- a/lib/Versions/ExpireManager.php +++ b/lib/Versions/ExpireManager.php @@ -31,17 +31,12 @@ 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[] */ @@ -52,7 +47,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(); }); @@ -97,8 +92,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 { @@ -108,12 +101,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 b65747951..a041832fb 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 555eb33e2..bdb5a7aaf 100644 --- a/lib/Versions/VersionsBackend.php +++ b/lib/Versions/VersionsBackend.php @@ -144,7 +144,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; @@ -184,10 +184,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(); @@ -243,9 +240,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 @@ + + + + + + + +