Passed
Push — master ( c5c219...cdd84d )
by Morris
12:06 queued 10s
created
apps/files_trashbin/lib/Trash/TrashManager.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -27,102 +27,102 @@
 block discarded – undo
27 27
 use OCP\IUser;
28 28
 
29 29
 class TrashManager implements ITrashManager {
30
-	/** @var ITrashBackend[] */
31
-	private $backends = [];
32
-
33
-	private $trashPaused = false;
34
-
35
-	public function registerBackend(string $storageType, ITrashBackend $backend) {
36
-		$this->backends[$storageType] = $backend;
37
-	}
38
-
39
-	/**
40
-	 * @return ITrashBackend[]
41
-	 */
42
-	private function getBackends(): array {
43
-		return $this->backends;
44
-	}
45
-
46
-	public function listTrashRoot(IUser $user): array {
47
-		$items = array_reduce($this->getBackends(), function (array $items, ITrashBackend $backend) use ($user) {
48
-			return array_merge($items, $backend->listTrashRoot($user));
49
-		}, []);
50
-		usort($items, function (ITrashItem $a, ITrashItem $b) {
51
-			return $a->getDeletedTime() - $b->getDeletedTime();
52
-		});
53
-		return $items;
54
-	}
55
-
56
-	private function getBackendForItem(ITrashItem $item) {
57
-		return $item->getTrashBackend();
58
-	}
59
-
60
-	public function listTrashFolder(ITrashItem $folder): array {
61
-		return $this->getBackendForItem($folder)->listTrashFolder($folder);
62
-	}
63
-
64
-	public function restoreItem(ITrashItem $item) {
65
-		return $this->getBackendForItem($item)->restoreItem($item);
66
-	}
67
-
68
-	public function removeItem(ITrashItem $item) {
69
-		$this->getBackendForItem($item)->removeItem($item);
70
-	}
71
-
72
-	/**
73
-	 * @param IStorage $storage
74
-	 * @return ITrashBackend
75
-	 * @throws BackendNotFoundException
76
-	 */
77
-	public function getBackendForStorage(IStorage $storage): ITrashBackend {
78
-		$fullType = get_class($storage);
79
-		$foundType = array_reduce(array_keys($this->backends), function ($type, $registeredType) use ($storage) {
80
-			if (
81
-				$storage->instanceOfStorage($registeredType) &&
82
-				($type === '' || is_subclass_of($registeredType, $type))
83
-			) {
84
-				return $registeredType;
85
-			} else {
86
-				return $type;
87
-			}
88
-		}, '');
89
-		if ($foundType === '') {
90
-			throw new BackendNotFoundException("Trash backend for $fullType not found");
91
-		} else {
92
-			return $this->backends[$foundType];
93
-		}
94
-	}
95
-
96
-	public function moveToTrash(IStorage $storage, string $internalPath): bool {
97
-		if ($this->trashPaused) {
98
-			return false;
99
-		}
100
-		try {
101
-			$backend = $this->getBackendForStorage($storage);
102
-			$this->trashPaused = true;
103
-			$result = $backend->moveToTrash($storage, $internalPath);
104
-			$this->trashPaused = false;
105
-			return $result;
106
-		} catch (BackendNotFoundException $e) {
107
-			return false;
108
-		}
109
-	}
110
-
111
-	public function getTrashNodeById(IUser $user, int $fileId) {
112
-		foreach ($this->backends as $backend) {
113
-			$item = $backend->getTrashNodeById($user, $fileId);
114
-			if ($item !== null) {
115
-				return $item;
116
-			}
117
-		}
118
-		return null;
119
-	}
120
-
121
-	public function pauseTrash() {
122
-		$this->trashPaused = true;
123
-	}
124
-
125
-	public function resumeTrash() {
126
-		$this->trashPaused = false;
127
-	}
30
+    /** @var ITrashBackend[] */
31
+    private $backends = [];
32
+
33
+    private $trashPaused = false;
34
+
35
+    public function registerBackend(string $storageType, ITrashBackend $backend) {
36
+        $this->backends[$storageType] = $backend;
37
+    }
38
+
39
+    /**
40
+     * @return ITrashBackend[]
41
+     */
42
+    private function getBackends(): array {
43
+        return $this->backends;
44
+    }
45
+
46
+    public function listTrashRoot(IUser $user): array {
47
+        $items = array_reduce($this->getBackends(), function (array $items, ITrashBackend $backend) use ($user) {
48
+            return array_merge($items, $backend->listTrashRoot($user));
49
+        }, []);
50
+        usort($items, function (ITrashItem $a, ITrashItem $b) {
51
+            return $a->getDeletedTime() - $b->getDeletedTime();
52
+        });
53
+        return $items;
54
+    }
55
+
56
+    private function getBackendForItem(ITrashItem $item) {
57
+        return $item->getTrashBackend();
58
+    }
59
+
60
+    public function listTrashFolder(ITrashItem $folder): array {
61
+        return $this->getBackendForItem($folder)->listTrashFolder($folder);
62
+    }
63
+
64
+    public function restoreItem(ITrashItem $item) {
65
+        return $this->getBackendForItem($item)->restoreItem($item);
66
+    }
67
+
68
+    public function removeItem(ITrashItem $item) {
69
+        $this->getBackendForItem($item)->removeItem($item);
70
+    }
71
+
72
+    /**
73
+     * @param IStorage $storage
74
+     * @return ITrashBackend
75
+     * @throws BackendNotFoundException
76
+     */
77
+    public function getBackendForStorage(IStorage $storage): ITrashBackend {
78
+        $fullType = get_class($storage);
79
+        $foundType = array_reduce(array_keys($this->backends), function ($type, $registeredType) use ($storage) {
80
+            if (
81
+                $storage->instanceOfStorage($registeredType) &&
82
+                ($type === '' || is_subclass_of($registeredType, $type))
83
+            ) {
84
+                return $registeredType;
85
+            } else {
86
+                return $type;
87
+            }
88
+        }, '');
89
+        if ($foundType === '') {
90
+            throw new BackendNotFoundException("Trash backend for $fullType not found");
91
+        } else {
92
+            return $this->backends[$foundType];
93
+        }
94
+    }
95
+
96
+    public function moveToTrash(IStorage $storage, string $internalPath): bool {
97
+        if ($this->trashPaused) {
98
+            return false;
99
+        }
100
+        try {
101
+            $backend = $this->getBackendForStorage($storage);
102
+            $this->trashPaused = true;
103
+            $result = $backend->moveToTrash($storage, $internalPath);
104
+            $this->trashPaused = false;
105
+            return $result;
106
+        } catch (BackendNotFoundException $e) {
107
+            return false;
108
+        }
109
+    }
110
+
111
+    public function getTrashNodeById(IUser $user, int $fileId) {
112
+        foreach ($this->backends as $backend) {
113
+            $item = $backend->getTrashNodeById($user, $fileId);
114
+            if ($item !== null) {
115
+                return $item;
116
+            }
117
+        }
118
+        return null;
119
+    }
120
+
121
+    public function pauseTrash() {
122
+        $this->trashPaused = true;
123
+    }
124
+
125
+    public function resumeTrash() {
126
+        $this->trashPaused = false;
127
+    }
128 128
 }
Please login to merge, or discard this patch.