Skip to content

Commit

Permalink
fix(psalm): Enable psalm level 3
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 20, 2024
1 parent b7ff9b0 commit 534cb3e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 12 deletions.
5 changes: 5 additions & 0 deletions lib/ACL/ACLManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\Files\IRootFolder;
use OCP\IUser;
use Psr\Log\LoggerInterface;
use RuntimeException;

class ACLManager {
private CappedMemoryCache $ruleCache;
Expand Down Expand Up @@ -88,6 +89,9 @@ private function getRelevantPaths(string $path): array {
$groupFolderId = (int)$groupFolderId;
/* Remove the date part */
$separatorPos = strrpos($rootTrashedItemName, '.d');
if ($separatorPos === false) {
throw new RuntimeException('Invalid trash item name ' . $rootTrashedItemName);
}
$rootTrashedItemDate = (int)substr($rootTrashedItemName, $separatorPos + 2);
$rootTrashedItemName = substr($rootTrashedItemName, 0, $separatorPos);
}
Expand All @@ -97,6 +101,7 @@ private function getRelevantPaths(string $path): array {
$path = dirname($path);
if ($fromTrashbin && ($path === '__groupfolders/trash')) {
/* We are in trash and hit the root folder, continue looking for ACLs on parent folders in original location */
/** @psalm-suppress PossiblyUndefinedVariable Variables are defined above */
$trashItemRow = $this->trashManager->getTrashItemByFileName($groupFolderId, $rootTrashedItemName, $rootTrashedItemDate);
$fromTrashbin = false;
if ($trashItemRow) {
Expand Down
4 changes: 4 additions & 0 deletions lib/ACL/ACLStorageWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public function opendir($path) {
}

$handle = parent::opendir($path);
if ($handle === false) {
return false;
}

$items = [];
while (($file = readdir($handle)) !== false) {
if ($file !== '.' && $file !== '..') {
Expand Down
1 change: 1 addition & 0 deletions lib/ACL/UserMapping/UserMappingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function mappingFromId(string $type, string $id): ?IUserMapping {
$mappingObject = ($type === 'group' ? $this->groupManager : $this->userManager)->get($id);
if ($mappingObject) {
$displayName = $mappingObject->getDisplayName();
/** @var 'user'|'group' $type */
return new UserMapping($type, $id, $displayName);
} else {
return null;
Expand Down
4 changes: 2 additions & 2 deletions lib/DAV/ACLPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use OCA\DAV\Connector\Sabre\Node;
use OCA\GroupFolders\ACL\Rule;
use OCA\GroupFolders\ACL\RuleManager;
use OCA\GroupFolders\ACL\UserMapping\UserMapping;
use OCA\GroupFolders\ACL\UserMapping\IUserMapping;
use OCA\GroupFolders\Folder\FolderManager;
use OCA\GroupFolders\Mount\GroupMountPoint;
use OCP\Constants;
Expand Down Expand Up @@ -145,7 +145,7 @@ public function propFind(PropFind $propFind, INode $node): void {
}
}

return array_map(fn (UserMapping $mapping, int $permissions, int $mask): Rule => new Rule(
return array_map(fn (IUserMapping $mapping, int $permissions, int $mask): Rule => new Rule(
$mapping,
$fileInfo->getId(),
$mask,
Expand Down
10 changes: 5 additions & 5 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function joinQueryWithFileCache(IQueryBuilder $query, int $rootStorageId
}

/**
* @return array<int, array{acl: bool, groups: array<string, array{displayName: string, type: string, permissions: integer}>, id: int, manage: array<array-key, array{displayname?: string, id?: string, type?: "group"|"user"|"circle"}>, mount_point: mixed, quota: int, size: int}>
* @return array<int, array{acl: bool, groups: array<string, array{displayName: string, type: string, permissions: integer}>, id: int, manage: array<array-key, array{displayname: string, id: string, type: "group"|"user"|"circle"}>, mount_point: mixed, quota: int, size: int}>
* @throws Exception
*/
public function getAllFoldersWithSize(int $rootStorageId): array {
Expand Down Expand Up @@ -130,7 +130,7 @@ public function getAllFoldersWithSize(int $rootStorageId): array {
}

/**
* @return array<int, array{acl: bool, groups: array<string, array{displayName: string, type: string, permissions: integer}>, id: int, manage: array<array-key, array{displayname?: string, id?: string, type?: "group"|"user"|"circle"}>, mount_point: mixed, quota: int, size: int}>
* @return array<int, array{acl: bool, groups: array<string, array{displayName: string, type: string, permissions: integer}>, id: int, manage: array<array-key, array{displayname: string, id: string, type: "group"|"user"|"circle"}>, mount_point: mixed, quota: int, size: int}>
* @throws Exception
*/
public function getAllFoldersForUserWithSize(int $rootStorageId, IUser $user): array {
Expand Down Expand Up @@ -212,7 +212,7 @@ private function getFolderMappings(int $id): array {
}

/**
* @return array{type?: 'user'|'group', id?: string, displayname?: string}[]
* @return array{type: 'user'|'group', id: string, displayname: string}[]
*/
private function getManageAcl(array $mappings): array {
return array_filter(array_map(function (array $entry): ?array {
Expand All @@ -231,15 +231,15 @@ private function getManageAcl(array $mappings): array {

$group = Server::get(IGroupManager::class)->get($entry['mapping_id']);
if ($group === null) {
return [];
return null;
}

return [
'type' => 'group',
'id' => $group->getGID(),
'displayname' => $group->getDisplayName()
];
}, $mappings), fn (?array $element): bool => $element !== null);
}, $mappings));
}

/**
Expand Down
7 changes: 3 additions & 4 deletions lib/Mount/GroupMountPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@
namespace OCA\GroupFolders\Mount;

use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage;
use OCP\Files\Mount\ISystemMountPoint;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageFactory;

class GroupMountPoint extends MountPoint implements ISystemMountPoint {
/**
* @param IStorage $storage
*/
public function __construct(
private int $folderId,
$storage,
IStorage $storage,
string $mountpoint,
?array $arguments = null,
?IStorageFactory $loader = null,
?array $mountOptions = null,
?int $mountId = null,
) {
/** @var Storage $storage */
parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId, MountProvider::class);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Mount/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public function getMount(
}

$cacheEntry = $this->getRootFolder()->getStorage()->getCache()->get($folder->getId());
if ($cacheEntry === false) {
return null;
}
}

$storage = $this->getRootFolder()->getStorage();
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<psalm
errorLevel="4"
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down

0 comments on commit 534cb3e

Please sign in to comment.