Skip to content

Commit cf5c51c

Browse files
committed
refactor: Add type-hinting to Node-API
Signed-off-by: Carl Schwan <[email protected]>
1 parent 8950f9f commit cf5c51c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1043
-1570
lines changed

apps/dav/lib/Connector/Sabre/Directory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
*/
88
namespace OCA\DAV\Connector\Sabre;
99

10+
use OC\Files\Mount\DummyMountPoint;
1011
use OC\Files\Mount\MoveableMount;
12+
use OC\Files\Storage\FailedStorage;
1113
use OC\Files\View;
1214
use OCA\DAV\AppInfo\Application;
1315
use OCA\DAV\Connector\Sabre\Exception\FileLocked;
@@ -106,9 +108,9 @@ public function createFile($name, $data = null) {
106108
$info = $this->fileView->getFileInfo($this->path . '/' . $name);
107109
if (!$info) {
108110
// use a dummy FileInfo which is acceptable here since it will be refreshed after the put is complete
109-
$info = new \OC\Files\FileInfo($path, null, null, [
111+
$info = new \OC\Files\FileInfo($path, new FailedStorage(['exception' => new \LogicException('Dummy storage') ]), '', [
110112
'type' => FileInfo::TYPE_FILE
111-
], null);
113+
], new DummyMountPoint());
112114
}
113115
$node = new File($this->fileView, $info);
114116

apps/dav/lib/Connector/Sabre/File.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ class File extends Node implements IFile {
5454

5555
/**
5656
* Sets up the node, expects a full path name
57-
*
58-
* @param View $view
59-
* @param FileInfo $info
60-
* @param ?\OCP\Share\IManager $shareManager
61-
* @param ?IRequest $request
62-
* @param ?IL10N $l10n
6357
*/
6458
public function __construct(View $view, FileInfo $info, ?IManager $shareManager = null, ?IRequest $request = null, ?IL10N $l10n = null) {
6559
parent::__construct($view, $info, $shareManager);

apps/dav/lib/Connector/Sabre/Node.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,20 @@
2727
abstract class Node implements \Sabre\DAV\INode {
2828
/**
2929
* The path to the current node
30-
*
31-
* @var string
32-
*/
33-
protected $path;
34-
35-
protected FileInfo $info;
36-
37-
/**
38-
* @var IManager
3930
*/
40-
protected $shareManager;
41-
31+
protected string $path = '';
4232
protected \OCP\Files\Node $node;
4333

4434
/**
4535
* Sets up the node, expects a full path name
4636
*/
4737
public function __construct(
4838
protected View $fileView,
49-
FileInfo $info,
50-
?IManager $shareManager = null,
39+
protected FileInfo $info,
40+
protected ?IManager $shareManager = null,
5141
) {
5242
$this->path = $this->fileView->getRelativePath($info->getPath());
53-
$this->info = $info;
54-
if ($shareManager) {
55-
$this->shareManager = $shareManager;
56-
} else {
43+
if (!$this->shareManager) {
5744
$this->shareManager = Server::get(\OCP\Share\IManager::class);
5845
}
5946
if ($info instanceof Folder || $info instanceof File) {
@@ -141,7 +128,7 @@ public function setName($name) {
141128
public function getLastModified() {
142129
$timestamp = $this->info->getMtime();
143130
if (!empty($timestamp)) {
144-
return (int)$timestamp;
131+
return $timestamp;
145132
}
146133
return $timestamp;
147134
}

apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\Files\ForbiddenException;
2222
use OCP\Files\InvalidPathException;
2323
use OCP\Files\Mount\IMountPoint;
24+
use OCP\Files\Storage\IStorage;
2425
use OCP\Files\StorageNotAvailableException;
2526
use PHPUnit\Framework\MockObject\MockObject;
2627
use Test\Traits\UserTrait;
@@ -68,6 +69,8 @@ protected function setUp(): void {
6869
parent::setUp();
6970

7071
$this->view = $this->createMock(View::class);
72+
$this->view->method('getAbsolutePath')->willReturnArgument(0);
73+
7174
$this->info = $this->createMock(FileInfo::class);
7275
$this->info->method('isReadable')
7376
->willReturn(true);
@@ -102,7 +105,7 @@ public function testDeleteRootFolderFails(): void {
102105
->willReturn(true);
103106
$this->view->expects($this->never())
104107
->method('rmdir');
105-
$dir = $this->getDir();
108+
$dir = $this->getDir('/');
106109
$dir->delete();
107110
}
108111

@@ -226,6 +229,8 @@ public function testGetChildrenNoPermission(): void {
226229
->method('isReadable')
227230
->willReturn(false);
228231

232+
$this->view->method('getRelativePath')->willReturnArgument(0);
233+
229234
$dir = new Directory($this->view, $info);
230235
$dir->getChildren();
231236
}
@@ -238,6 +243,8 @@ public function testGetChildNoPermission(): void {
238243
->method('isReadable')
239244
->willReturn(false);
240245

246+
$this->view->method('getRelativePath')->willReturnArgument(0);
247+
241248
$dir = new Directory($this->view, $this->info);
242249
$dir->getChild('test');
243250
}
@@ -250,6 +257,8 @@ public function testGetChildThrowStorageNotAvailableException(): void {
250257
->method('getFileInfo')
251258
->willThrowException(new StorageNotAvailableException());
252259

260+
$this->view->method('getRelativePath')->willReturnArgument(0);
261+
253262
$dir = new Directory($this->view, $this->info);
254263
$dir->getChild('.');
255264
}
@@ -264,6 +273,8 @@ public function testGetChildThrowInvalidPath(): void {
264273
$this->view->expects($this->never())
265274
->method('getFileInfo');
266275

276+
$this->view->method('getRelativePath')->willReturnArgument(0);
277+
267278
$dir = new Directory($this->view, $this->info);
268279
$dir->getChild('.');
269280
}
@@ -421,12 +432,12 @@ public static function moveSuccessProvider(): array {
421432
private function moveTest(string $source, string $destination, array $updatables, array $deletables): void {
422433
$view = new TestViewDirectory($updatables, $deletables);
423434

424-
$sourceInfo = new FileInfo($source, null, null, [
435+
$sourceInfo = new FileInfo($source, $this->createMock(IStorage::class), '', [
425436
'type' => FileInfo::TYPE_FOLDER,
426-
], null);
427-
$targetInfo = new FileInfo(dirname($destination), null, null, [
437+
], $this->createMock(IMountPoint::class));
438+
$targetInfo = new FileInfo(dirname($destination), $this->createMock(IStorage::class), '', [
428439
'type' => FileInfo::TYPE_FOLDER,
429-
], null);
440+
], $this->createMock(IMountPoint::class));
430441

431442
$sourceNode = new Directory($view, $sourceInfo);
432443
$targetNode = $this->getMockBuilder(Directory::class)
@@ -451,8 +462,8 @@ public function testFailingMove(): void {
451462

452463
$view = new TestViewDirectory($updatables, $deletables);
453464

454-
$sourceInfo = new FileInfo($source, null, null, ['type' => FileInfo::TYPE_FOLDER], null);
455-
$targetInfo = new FileInfo(dirname($destination), null, null, ['type' => FileInfo::TYPE_FOLDER], null);
465+
$sourceInfo = new FileInfo($source, $this->createMock(IStorage::class), '', ['type' => FileInfo::TYPE_FOLDER], $this->createMock(IMountPoint::class));
466+
$targetInfo = new FileInfo(dirname($destination), $this->createMock(IStorage::class), '', ['type' => FileInfo::TYPE_FOLDER], $this->createMock(IMountPoint::class));
456467

457468
$sourceNode = new Directory($view, $sourceInfo);
458469
$targetNode = $this->getMockBuilder(Directory::class)

0 commit comments

Comments
 (0)