Skip to content

Commit 86cec98

Browse files
committed
refactor(trashbin): Replace mapTrashItems by mapTrashItem
Only take one argument and instead call this with array map Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 1e4637e commit 86cec98

3 files changed

Lines changed: 22 additions & 37 deletions

File tree

apps/files_trashbin/lib/Sabre/TrashRoot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private function trashItemToTrashNode(ITrashItem $entry): ITrash&INode {
8383
return match ($entry->getType()) {
8484
FileInfo::TYPE_FOLDER => new TrashFolder($this->trashManager, $entry),
8585
FileInfo::TYPE_FILE => new TrashFile($this->trashManager, $entry),
86-
default => throw new RuntimeException("Invalid FileInfo object"),
86+
default => throw new RuntimeException('Invalid FileInfo object'),
8787
};
8888
}
8989
}

apps/files_trashbin/lib/Trash/LegacyTrashBackend.php

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,45 @@ public function __construct(
2929
) {
3030
}
3131

32-
/**
33-
* @param array $items
34-
* @param IUser $user
35-
* @param ITrashItem $parent
36-
* @return ITrashItem[]
37-
*/
38-
private function mapTrashItems(array $items, IUser $user, ?ITrashItem $parent = null): array {
32+
private function mapTrashItem(FileInfo $file, IUser $user, ?ITrashItem $parent = null): ITrashItem {
3933
$parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
4034
$isRoot = $parent === null;
41-
return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
42-
$originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName();
43-
if (!$originalLocation) {
44-
$originalLocation = $file->getName();
45-
}
46-
/** @psalm-suppress UndefinedInterfaceMethod */
47-
$deletedBy = $this->userManager->get($file['deletedBy']) ?? $parent?->getDeletedBy();
48-
$trashFilename = Trashbin::getTrashFilename($file->getName(), $file->getMtime());
49-
return new TrashItem(
50-
$this,
51-
$originalLocation,
52-
$file->getMTime(),
53-
$parentTrashPath . '/' . ($isRoot ? $trashFilename : $file->getName()),
54-
$file,
55-
$user,
56-
$deletedBy,
57-
);
58-
}, $items);
35+
36+
$originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName();
37+
if (!$originalLocation) {
38+
$originalLocation = $file->getName();
39+
}
40+
/** @psalm-suppress UndefinedInterfaceMethod */
41+
$deletedBy = $this->userManager->get($file['deletedBy']) ?? $parent?->getDeletedBy();
42+
$trashFilename = Trashbin::getTrashFilename($file->getName(), $file->getMtime());
43+
return new TrashItem(
44+
$this,
45+
$originalLocation,
46+
$file->getMTime(),
47+
$parentTrashPath . '/' . ($isRoot ? $trashFilename : $file->getName()),
48+
$file,
49+
$user,
50+
$deletedBy,
51+
);
5952
}
6053

6154
public function listTrashRoot(IUser $user): array {
6255
$entries = Helper::getTrashFiles('/', $user->getUID());
63-
return $this->mapTrashItems($entries, $user);
56+
return array_map(fn (FileInfo $fileInfo): ITrashItem => $this->mapTrashItem($fileInfo, $user), $entries);
6457
}
6558

6659
public function getTrashRootItem(IUser $user, string $name): ?ITrashItem {
6760
$entry = Helper::getTrashFile('/', $user->getUID(), $name);
6861
if ($entry === null) {
6962
return null;
7063
}
71-
return $this->mapTrashItems([$entry], $user)[0];
64+
return $this->mapTrashItem($entry, $user);
7265
}
7366

7467
public function listTrashFolder(ITrashItem $folder): array {
7568
$user = $folder->getUser();
7669
$entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
77-
return $this->mapTrashItems($entries, $user, $folder);
70+
return array_map(fn (FileInfo $fileInfo): ITrashItem => $this->mapTrashItem($fileInfo, $user, $folder), $entries);
7871
}
7972

8073
public function restoreItem(ITrashItem $item) {

build/psalm-baseline.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,14 +1828,6 @@
18281828
<code><![CDATA[INode]]></code>
18291829
</MismatchingDocblockReturnType>
18301830
</file>
1831-
<file src="apps/files_trashbin/lib/Sabre/TrashRoot.php">
1832-
<InvalidReturnStatement>
1833-
<code><![CDATA[$entry]]></code>
1834-
</InvalidReturnStatement>
1835-
<InvalidReturnType>
1836-
<code><![CDATA[ITrash]]></code>
1837-
</InvalidReturnType>
1838-
</file>
18391831
<file src="apps/files_trashbin/lib/Storage.php">
18401832
<DeprecatedMethod>
18411833
<code><![CDATA[dispatch]]></code>

0 commit comments

Comments
 (0)