Skip to content

Commit

Permalink
refactor: Add missing type declarations
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 19, 2024
1 parent c67b4f4 commit 2453391
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/DAV/PropFindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function propFind(PropFind $propFind, INode $node): void {
);
$propFind->handle(
self::GROUP_FOLDER_ID_PROPERTYNAME,
fn () => $node->getFolderId()
fn (): int => $node->getFolderId()
);
}
}
Expand Down
3 changes: 1 addition & 2 deletions lib/Versions/VersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ private function getFolderIdForFile(FileInfo $file): int {
} elseif ($storage->instanceOfStorage(GroupFolderStorage::class)) {
/** @var GroupFolderStorage $storage */
return $storage->getFolderId();
} else {
throw new \LogicException('groupfolder version backend called for non groupfolder file');
}
throw new \LogicException('groupfolder version backend called for non groupfolder file');
}

public function getVersionFolderForFile(FileInfo $file): Folder {
Expand Down
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
])
->withPreparedSets(
deadCode: true,
)
->withTypeCoverageLevel(0);
typeDeclarations: true,
);
7 changes: 3 additions & 4 deletions tests/ACL/ACLCacheWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ class ACLCacheWrapperTest extends TestCase {
private $aclManager;
/** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
private $source;
/** @var ACLCacheWrapper */
private $cache;
private $aclPermissions = [];
private ?ACLCacheWrapper $cache = null;
private array $aclPermissions = [];

protected function setUp(): void {
parent::setUp();
Expand All @@ -39,7 +38,7 @@ protected function setUp(): void {
$this->cache = new ACLCacheWrapper($this->source, $this->aclManager, false);
}

public function testHideNonRead() {
public function testHideNonRead(): void {
$this->source->method('getFolderContentsById')
->willReturn([
new CacheEntry([
Expand Down
4 changes: 2 additions & 2 deletions tests/ACL/ACLManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ protected function setUp(): void {
$this->dummyMapping = $this->createMapping('dummy');

$this->ruleManager->method('getRulesForFilesByPath')
->willReturnCallback(function (IUser $user, int $storageId, array $paths) {
->willReturnCallback(function (IUser $user, int $storageId, array $paths): array {
// fill with empty in case no rule was found
$rules = array_fill_keys($paths, []);
$actualRules = array_filter($this->rules, function (string $path) use ($paths) {
$actualRules = array_filter($this->rules, function (string $path) use ($paths): bool {
return array_search($path, $paths) !== false;
}, ARRAY_FILTER_USE_KEY);

Expand Down
2 changes: 1 addition & 1 deletion tests/ACL/ACLScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private function getAclManager(array $rules): ACLManager {
return $manager;
}

public function testScanAclStorage() {
public function testScanAclStorage(): void {
$baseStorage = new Temporary([]);
$baseStorage->mkdir('foo');
$baseStorage->mkdir('foo/bar');
Expand Down
15 changes: 6 additions & 9 deletions tests/ACL/ACLStorageWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
use OCA\GroupFolders\ACL\ACLManager;
use OCA\GroupFolders\ACL\ACLStorageWrapper;
use OCP\Constants;
use OCP\Files\Storage\IStorage;
use Test\TestCase;

class ACLStorageWrapperTest extends TestCase {
/** @var ACLManager|\PHPUnit_Framework_MockObject_MockObject */
private $aclManager;
/** @var IStorage */
private $source;
/** @var ACLStorageWrapper */
private $storage;
private $aclPermissions = [];
private ?Temporary $source = null;
private ?ACLStorageWrapper $storage = null;
private array $aclPermissions = [];

protected function setUp(): void {
parent::setUp();
Expand All @@ -40,7 +37,7 @@ protected function setUp(): void {
]);
}

public function testNoReadImpliesNothing() {
public function testNoReadImpliesNothing(): void {
$this->source->mkdir('foo');
$this->aclPermissions['foo'] = Constants::PERMISSION_ALL - Constants::PERMISSION_READ;

Expand All @@ -50,7 +47,7 @@ public function testNoReadImpliesNothing() {
$this->assertEquals(false, $this->storage->isSharable('foo'));
}

public function testOpenDir() {
public function testOpenDir(): void {
$this->source->mkdir('foo');
$this->source->touch('foo/file1');
$this->source->touch('foo/file2');
Expand All @@ -73,7 +70,7 @@ public function testOpenDir() {
$this->assertEquals($expected, $result);
}

public function testMove() {
public function testMove(): void {
$this->source->mkdir('foo');
$this->source->touch('file1');

Expand Down
15 changes: 7 additions & 8 deletions tests/ACL/RuleManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
class RuleManagerTest extends TestCase {
/** @var \PHPUnit_Framework_MockObject_MockObject | IUserMappingManager */
private $userMappingManager;
/** @var RuleManager */
private $ruleManager;
private ?RuleManager $ruleManager = null;
/** @var \PHPUnit_Framework_MockObject_MockObject | IUser */
private $user;

Expand All @@ -42,7 +41,7 @@ protected function setUp(): void {
$this->userMappingManager = $this->createMock(IUserMappingManager::class);
$this->userMappingManager->expects($this->any())
->method('mappingFromId')
->willReturnCallback(function ($type, $id) {
->willReturnCallback(function ($type, $id): UserMapping {
if ($type === 'user') {
return new UserMapping($type, $id, 'The User');
} else {
Expand All @@ -54,7 +53,7 @@ protected function setUp(): void {
$this->ruleManager = new RuleManager(\OC::$server->getDatabaseConnection(), $this->userMappingManager, $this->eventDispatcher);
}

public function testGetSetRule() {
public function testGetSetRule(): void {
$mapping = new UserMapping('user', '1', 'The User');
$this->userMappingManager->expects($this->any())
->method('getMappingsForUser')
Expand Down Expand Up @@ -104,7 +103,7 @@ public function testGetSetRule() {
$this->ruleManager->deleteRule($rule);
}

public function testGetMultiple() {
public function testGetMultiple(): void {
$mapping1 = new UserMapping('test', '1');
$mapping2 = new UserMapping('test', '2');
$this->userMappingManager->expects($this->any())
Expand All @@ -131,7 +130,7 @@ public function testGetMultiple() {
$this->ruleManager->deleteRule($rule3);
}

public function testGetByPath() {
public function testGetByPath(): void {
$storage = new Temporary([]);
$storage->mkdir('foo');
$storage->mkdir('foo/bar');
Expand Down Expand Up @@ -166,7 +165,7 @@ public function testGetByPath() {
$this->ruleManager->deleteRule($rule2);
}

public function testGetByPathMore() {
public function testGetByPathMore(): void {
$storage = new Temporary([]);
$storage->mkdir('foo');
$paths = [];
Expand Down Expand Up @@ -207,7 +206,7 @@ public function testGetByPathMore() {
$this->ruleManager->deleteRule($rule);
}

public function testGetByParent() {
public function testGetByParent(): void {
$storage = new Temporary([]);
$storage->mkdir('foo');
$storage->mkdir('foo/bar');
Expand Down
6 changes: 3 additions & 3 deletions tests/ACL/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function permissionsProvider() {
/**
* @dataProvider permissionsProvider
*/
public function testApplyPermissions($input, $mask, $permissions, $expected) {
public function testApplyPermissions($input, $mask, $permissions, $expected): void {
$rule = new Rule($this->createMock(IUserMapping::class), 0, $mask, $permissions);
$this->assertEquals($expected, $rule->applyPermissions($input));
}
Expand Down Expand Up @@ -56,8 +56,8 @@ public function mergeRulesProvider() {
/**
* @dataProvider mergeRulesProvider
*/
public function testMergeRules($inputs, $expectedMask, $expectedPermissions) {
$inputRules = array_map(function (array $input) {
public function testMergeRules($inputs, $expectedMask, $expectedPermissions): void {
$inputRules = array_map(function (array $input): Rule {
return new Rule($this->createMock(IUserMapping::class), 0, $input[0], $input[1]);
}, $inputs);

Expand Down
36 changes: 18 additions & 18 deletions tests/Folder/FolderManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ protected function setUp(): void {
$this->clean();
}

private function clean() {
private function clean(): void {
$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query->delete('group_folders')->execute();

$query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$query->delete('group_folders_groups')->execute();
}

private function assertHasFolders($folders) {
private function assertHasFolders(array $folders): void {
$existingFolders = array_values($this->manager->getAllFolders());
usort($existingFolders, function ($a, $b) {
usort($existingFolders, function (array $a, array $b): int {
return strcmp($a['mount_point'], $b['mount_point']);
});
usort($folders, function ($a, $b) {
usort($folders, function (array $a, array $b): int {
return strcmp($a['mount_point'], $b['mount_point']);
});

Expand All @@ -89,15 +89,15 @@ private function assertHasFolders($folders) {
$this->assertEquals($folders, $existingFolders);
}

public function testCreateFolder() {
public function testCreateFolder(): void {
$this->manager->createFolder('foo');

$this->assertHasFolders([
['mount_point' => 'foo', 'groups' => []]
]);
}

public function testSetMountpoint() {
public function testSetMountpoint(): void {
$folderId1 = $this->manager->createFolder('foo');
$this->manager->createFolder('bar');

Expand All @@ -109,7 +109,7 @@ public function testSetMountpoint() {
]);
}

public function testAddApplicable() {
public function testAddApplicable(): void {
$folderId1 = $this->manager->createFolder('foo');
$folderId2 = $this->manager->createFolder('bar');
$this->manager->addApplicableGroup($folderId1, 'g1');
Expand Down Expand Up @@ -154,7 +154,7 @@ public function testAddApplicable() {
);
}

public function testSetPermissions() {
public function testSetPermissions(): void {
$folderId1 = $this->manager->createFolder('foo');
$this->manager->addApplicableGroup($folderId1, 'g1');
$this->manager->addApplicableGroup($folderId1, 'g2');
Expand Down Expand Up @@ -182,7 +182,7 @@ public function testSetPermissions() {
);
}

public function testRemoveApplicable() {
public function testRemoveApplicable(): void {
$folderId1 = $this->manager->createFolder('foo');
$folderId2 = $this->manager->createFolder('bar');
$this->manager->addApplicableGroup($folderId1, 'g1');
Expand Down Expand Up @@ -225,7 +225,7 @@ public function testRemoveApplicable() {
);
}

public function testRemoveFolder() {
public function testRemoveFolder(): void {
$folderId1 = $this->manager->createFolder('foo');
$this->manager->createFolder('bar');

Expand All @@ -236,7 +236,7 @@ public function testRemoveFolder() {
]);
}

public function testRenameFolder() {
public function testRenameFolder(): void {
$folderId1 = $this->manager->createFolder('foo');
$this->manager->createFolder('other');

Expand All @@ -248,7 +248,7 @@ public function testRenameFolder() {
]);
}

public function testSetACL() {
public function testSetACL(): void {
$folderId1 = $this->manager->createFolder('foo');
$this->manager->createFolder('other');

Expand All @@ -267,7 +267,7 @@ public function testSetACL() {
]);
}

public function testGetFoldersForGroup() {
public function testGetFoldersForGroup(): void {
$folderId1 = $this->manager->createFolder('foo');
$this->manager->addApplicableGroup($folderId1, 'g1');
$this->manager->addApplicableGroup($folderId1, 'g2');
Expand All @@ -280,7 +280,7 @@ public function testGetFoldersForGroup() {
$this->assertEquals(2, $folder['permissions']);
}

public function testGetFoldersForGroups() {
public function testGetFoldersForGroups(): void {
$folderId1 = $this->manager->createFolder('foo');
$this->manager->addApplicableGroup($folderId1, 'g1');
$this->manager->addApplicableGroup($folderId1, 'g2');
Expand Down Expand Up @@ -309,13 +309,13 @@ protected function getUser($groups = []) {
return $user;
}

public function testGetFoldersForUserEmpty() {
public function testGetFoldersForUserEmpty(): void {
$folders = $this->manager->getFoldersForUser($this->getUser());
$this->assertEquals([], $folders);
}


public function testGetFoldersForUserSimple() {
public function testGetFoldersForUserSimple(): void {
$db = $this->createMock(IDBConnection::class);
/** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(FolderManager::class)
Expand All @@ -338,7 +338,7 @@ public function testGetFoldersForUserSimple() {
$this->assertEquals([$folder], $folders);
}

public function testGetFoldersForUserMerge() {
public function testGetFoldersForUserMerge(): void {
$db = $this->createMock(IDBConnection::class);
/** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(FolderManager::class)
Expand Down Expand Up @@ -374,7 +374,7 @@ public function testGetFoldersForUserMerge() {
], $folders);
}

public function testGetFolderPermissionsForUserMerge() {
public function testGetFolderPermissionsForUserMerge(): void {
$db = $this->createMock(IDBConnection::class);
/** @var FolderManager|\PHPUnit_Framework_MockObject_MockObject $manager */
$manager = $this->getMockBuilder(FolderManager::class)
Expand Down
8 changes: 4 additions & 4 deletions tests/Trash/TrashBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private function createNoReadRule(string $userId, int $fileId): Rule {
);
}

public function testHideTrashItemAcl() {
public function testHideTrashItemAcl(): void {
$this->loginAsUser('manager');

$restricted = $this->managerUserFolder->newFile("{$this->folderName}/restricted.txt", 'content');
Expand All @@ -126,7 +126,7 @@ public function testHideTrashItemAcl() {
$this->logout();
}

public function testHideItemInDeletedFolderAcl() {
public function testHideItemInDeletedFolderAcl(): void {
$this->loginAsUser('manager');

$folder = $this->managerUserFolder->newFolder("{$this->folderName}/folder");
Expand Down Expand Up @@ -155,7 +155,7 @@ public function testHideItemInDeletedFolderAcl() {
$this->logout();
}

public function testHideDeletedTrashItemInDeletedFolderAcl() {
public function testHideDeletedTrashItemInDeletedFolderAcl(): void {
$this->loginAsUser('manager');

$folder = $this->managerUserFolder->newFolder("{$this->folderName}/restricted");
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testHideDeletedTrashItemInDeletedFolderAcl() {
$this->logout();
}

public function testHideDeletedTrashItemInDeletedParentFolderAcl() {
public function testHideDeletedTrashItemInDeletedParentFolderAcl(): void {
$this->loginAsUser('manager');

$parent = $this->managerUserFolder->newFolder("{$this->folderName}/parent");
Expand Down

0 comments on commit 2453391

Please sign in to comment.