Skip to content

Commit 31dd442

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 e62ca8c commit 31dd442

3 files changed

Lines changed: 28 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: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,12 +1784,18 @@
17841784
<file src="apps/files_trashbin/lib/Helper.php">
17851785
<InternalClass>
17861786
<code><![CDATA[new View('/' . $user . '/files_trashbin/files')]]></code>
1787+
<code><![CDATA[new View('/' . $user . '/files_trashbin/files')]]></code>
17871788
</InternalClass>
17881789
<InternalMethod>
17891790
<code><![CDATA[getAbsolutePath]]></code>
17901791
<code><![CDATA[getAbsolutePath]]></code>
1792+
<code><![CDATA[getAbsolutePath]]></code>
1793+
<code><![CDATA[getAbsolutePath]]></code>
1794+
<code><![CDATA[getMount]]></code>
17911795
<code><![CDATA[getMount]]></code>
17921796
<code><![CDATA[is_dir]]></code>
1797+
<code><![CDATA[is_dir]]></code>
1798+
<code><![CDATA[new View('/' . $user . '/files_trashbin/files')]]></code>
17931799
<code><![CDATA[new View('/' . $user . '/files_trashbin/files')]]></code>
17941800
</InternalMethod>
17951801
</file>
@@ -1822,14 +1828,6 @@
18221828
<code><![CDATA[INode]]></code>
18231829
</MismatchingDocblockReturnType>
18241830
</file>
1825-
<file src="apps/files_trashbin/lib/Sabre/TrashRoot.php">
1826-
<InvalidReturnStatement>
1827-
<code><![CDATA[$entry]]></code>
1828-
</InvalidReturnStatement>
1829-
<InvalidReturnType>
1830-
<code><![CDATA[ITrash]]></code>
1831-
</InvalidReturnType>
1832-
</file>
18331831
<file src="apps/files_trashbin/lib/Sabre/TrashbinPlugin.php">
18341832
<InternalMethod>
18351833
<code><![CDATA[free_space]]></code>

0 commit comments

Comments
 (0)