Passed
Push — master ( 9d4e71...60ae0a )
by Roeland
10:19
created
apps/files_trashbin/lib/Trash/LegacyTrashBackend.php 2 patches
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -33,100 +33,100 @@
 block discarded – undo
33 33
 use OCP\IUser;
34 34
 
35 35
 class LegacyTrashBackend implements ITrashBackend {
36
-	/** @var array */
37
-	private $deletedFiles = [];
36
+    /** @var array */
37
+    private $deletedFiles = [];
38 38
 
39
-	/** @var IRootFolder */
40
-	private $rootFolder;
39
+    /** @var IRootFolder */
40
+    private $rootFolder;
41 41
 
42
-	public function __construct(IRootFolder $rootFolder) {
43
-		$this->rootFolder = $rootFolder;
44
-	}
42
+    public function __construct(IRootFolder $rootFolder) {
43
+        $this->rootFolder = $rootFolder;
44
+    }
45 45
 
46
-	/**
47
-	 * @param array $items
48
-	 * @param IUser $user
49
-	 * @param ITrashItem $parent
50
-	 * @return ITrashItem[]
51
-	 */
52
-	private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array {
53
-		$parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
54
-		$isRoot = $parent === null;
55
-		return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
56
-			$originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName();
57
-			if (!$originalLocation) {
58
-				$originalLocation = $file->getName();
59
-			}
60
-			return new TrashItem(
61
-				$this,
62
-				$originalLocation,
63
-				$file->getMTime(),
64
-				$parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
65
-				$file,
66
-				$user
67
-			);
68
-		}, $items);
69
-	}
46
+    /**
47
+     * @param array $items
48
+     * @param IUser $user
49
+     * @param ITrashItem $parent
50
+     * @return ITrashItem[]
51
+     */
52
+    private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array {
53
+        $parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
54
+        $isRoot = $parent === null;
55
+        return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
56
+            $originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName();
57
+            if (!$originalLocation) {
58
+                $originalLocation = $file->getName();
59
+            }
60
+            return new TrashItem(
61
+                $this,
62
+                $originalLocation,
63
+                $file->getMTime(),
64
+                $parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
65
+                $file,
66
+                $user
67
+            );
68
+        }, $items);
69
+    }
70 70
 
71
-	public function listTrashRoot(IUser $user): array {
72
-		$entries = Helper::getTrashFiles('/', $user->getUID());
73
-		return $this->mapTrashItems($entries, $user);
74
-	}
71
+    public function listTrashRoot(IUser $user): array {
72
+        $entries = Helper::getTrashFiles('/', $user->getUID());
73
+        return $this->mapTrashItems($entries, $user);
74
+    }
75 75
 
76
-	public function listTrashFolder(ITrashItem $folder): array {
77
-		$user = $folder->getUser();
78
-		$entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
79
-		return $this->mapTrashItems($entries, $user ,$folder);
80
-	}
76
+    public function listTrashFolder(ITrashItem $folder): array {
77
+        $user = $folder->getUser();
78
+        $entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
79
+        return $this->mapTrashItems($entries, $user ,$folder);
80
+    }
81 81
 
82
-	public function restoreItem(ITrashItem $item) {
83
-		Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null);
84
-	}
82
+    public function restoreItem(ITrashItem $item) {
83
+        Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null);
84
+    }
85 85
 
86
-	public function removeItem(ITrashItem $item) {
87
-		$user = $item->getUser();
88
-		if ($item->isRootItem()) {
89
-			$path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
90
-			Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());
91
-		} else {
92
-			Trashbin::delete($item->getTrashPath(), $user->getUID(), null);
93
-		}
86
+    public function removeItem(ITrashItem $item) {
87
+        $user = $item->getUser();
88
+        if ($item->isRootItem()) {
89
+            $path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
90
+            Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());
91
+        } else {
92
+            Trashbin::delete($item->getTrashPath(), $user->getUID(), null);
93
+        }
94 94
 
95
-	}
95
+    }
96 96
 
97
-	public function moveToTrash(IStorage $storage, string $internalPath): bool {
98
-		if (!$storage instanceof Storage) {
99
-			return false;
100
-		}
101
-		$normalized = Filesystem::normalizePath($storage->getMountPoint() . '/' . $internalPath, true, false, true);
102
-		$view = Filesystem::getView();
103
-		if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) {
104
-			$this->deletedFiles[$normalized] = $normalized;
105
-			if ($filesPath = $view->getRelativePath($normalized)) {
106
-				$filesPath = trim($filesPath, '/');
107
-				$result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath);
108
-			} else {
109
-				$result = false;
110
-			}
111
-			unset($this->deletedFiles[$normalized]);
112
-		} else {
113
-			$result = false;
114
-		}
97
+    public function moveToTrash(IStorage $storage, string $internalPath): bool {
98
+        if (!$storage instanceof Storage) {
99
+            return false;
100
+        }
101
+        $normalized = Filesystem::normalizePath($storage->getMountPoint() . '/' . $internalPath, true, false, true);
102
+        $view = Filesystem::getView();
103
+        if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) {
104
+            $this->deletedFiles[$normalized] = $normalized;
105
+            if ($filesPath = $view->getRelativePath($normalized)) {
106
+                $filesPath = trim($filesPath, '/');
107
+                $result = \OCA\Files_Trashbin\Trashbin::move2trash($filesPath);
108
+            } else {
109
+                $result = false;
110
+            }
111
+            unset($this->deletedFiles[$normalized]);
112
+        } else {
113
+            $result = false;
114
+        }
115 115
 
116
-		return $result;
117
-	}
116
+        return $result;
117
+    }
118 118
 
119
-	public function getTrashNodeById(IUser $user, int $fileId) {
120
-		try {
121
-			$userFolder = $this->rootFolder->getUserFolder($user->getUID());
122
-			$trash = $userFolder->getParent()->get('files_trashbin/files');
123
-			$trashFiles = $trash->getById($fileId);
124
-			if (!$trashFiles) {
125
-				return null;
126
-			}
127
-			return $trashFiles ? array_pop($trashFiles) : null;
128
-		} catch (NotFoundException $e) {
129
-			return null;
130
-		}
131
-	}
119
+    public function getTrashNodeById(IUser $user, int $fileId) {
120
+        try {
121
+            $userFolder = $this->rootFolder->getUserFolder($user->getUID());
122
+            $trash = $userFolder->getParent()->get('files_trashbin/files');
123
+            $trashFiles = $trash->getById($fileId);
124
+            if (!$trashFiles) {
125
+                return null;
126
+            }
127
+            return $trashFiles ? array_pop($trashFiles) : null;
128
+        } catch (NotFoundException $e) {
129
+            return null;
130
+        }
131
+    }
132 132
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array {
53 53
 		$parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
54 54
 		$isRoot = $parent === null;
55
-		return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
56
-			$originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName();
55
+		return array_map(function(FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
56
+			$originalLocation = $isRoot ? $file['extraData'] : $parent->getOriginalLocation().'/'.$file->getName();
57 57
 			if (!$originalLocation) {
58 58
 				$originalLocation = $file->getName();
59 59
 			}
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 				$this,
62 62
 				$originalLocation,
63 63
 				$file->getMTime(),
64
-				$parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
64
+				$parentTrashPath.'/'.$file->getName().($isRoot ? '.d'.$file->getMtime() : ''),
65 65
 				$file,
66 66
 				$user
67 67
 			);
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	public function listTrashFolder(ITrashItem $folder): array {
77 77
 		$user = $folder->getUser();
78 78
 		$entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
79
-		return $this->mapTrashItems($entries, $user ,$folder);
79
+		return $this->mapTrashItems($entries, $user, $folder);
80 80
 	}
81 81
 
82 82
 	public function restoreItem(ITrashItem $item) {
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	public function removeItem(ITrashItem $item) {
87 87
 		$user = $item->getUser();
88 88
 		if ($item->isRootItem()) {
89
-			$path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
89
+			$path = substr($item->getTrashPath(), 0, -strlen('.d'.$item->getDeletedTime()));
90 90
 			Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());
91 91
 		} else {
92 92
 			Trashbin::delete($item->getTrashPath(), $user->getUID(), null);
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		if (!$storage instanceof Storage) {
99 99
 			return false;
100 100
 		}
101
-		$normalized = Filesystem::normalizePath($storage->getMountPoint() . '/' . $internalPath, true, false, true);
101
+		$normalized = Filesystem::normalizePath($storage->getMountPoint().'/'.$internalPath, true, false, true);
102 102
 		$view = Filesystem::getView();
103 103
 		if (!isset($this->deletedFiles[$normalized]) && $view instanceof View) {
104 104
 			$this->deletedFiles[$normalized] = $normalized;
Please login to merge, or discard this patch.