Passed
Push — master ( ee3dc5...83330b )
by Roeland
31:33 queued 16:31
created
lib/private/Files/Search/SearchBinaryOperator.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -25,33 +25,33 @@
 block discarded – undo
25 25
 use OCP\Files\Search\ISearchOperator;
26 26
 
27 27
 class SearchBinaryOperator implements ISearchBinaryOperator {
28
-	/** @var string */
29
-	private $type;
30
-	/** @var ISearchOperator[] */
31
-	private $arguments;
28
+    /** @var string */
29
+    private $type;
30
+    /** @var ISearchOperator[] */
31
+    private $arguments;
32 32
 
33
-	/**
34
-	 * SearchBinaryOperator constructor.
35
-	 *
36
-	 * @param string $type
37
-	 * @param ISearchOperator[] $arguments
38
-	 */
39
-	public function __construct($type, array $arguments) {
40
-		$this->type = $type;
41
-		$this->arguments = $arguments;
42
-	}
33
+    /**
34
+     * SearchBinaryOperator constructor.
35
+     *
36
+     * @param string $type
37
+     * @param ISearchOperator[] $arguments
38
+     */
39
+    public function __construct($type, array $arguments) {
40
+        $this->type = $type;
41
+        $this->arguments = $arguments;
42
+    }
43 43
 
44
-	/**
45
-	 * @return string
46
-	 */
47
-	public function getType() {
48
-		return $this->type;
49
-	}
44
+    /**
45
+     * @return string
46
+     */
47
+    public function getType() {
48
+        return $this->type;
49
+    }
50 50
 
51
-	/**
52
-	 * @return ISearchOperator[]
53
-	 */
54
-	public function getArguments() {
55
-		return $this->arguments;
56
-	}
51
+    /**
52
+     * @return ISearchOperator[]
53
+     */
54
+    public function getArguments() {
55
+        return $this->arguments;
56
+    }
57 57
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/appinfo/routes.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -23,18 +23,18 @@
 block discarded – undo
23 23
  */
24 24
 
25 25
 return [
26
-	'routes' => [
27
-		['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'],
28
-		['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
29
-	],
30
-	'ocs' => [
31
-		['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'],
32
-		['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'],
33
-		['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'],
34
-		['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'],
35
-		['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'],
36
-		['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'],
37
-		['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'],
38
-		['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'],
39
-	],
26
+    'routes' => [
27
+        ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'],
28
+        ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
29
+    ],
30
+    'ocs' => [
31
+        ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'],
32
+        ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'],
33
+        ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'],
34
+        ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'],
35
+        ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'],
36
+        ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'],
37
+        ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'],
38
+        ['root' => '/cloud', 'name' => 'RequestHandler#move', 'url' => '/shares/{id}/move', 'verb' => 'POST'],
39
+    ],
40 40
 ];
Please login to merge, or discard this patch.
apps/dav/appinfo/v2/remote.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
  */
22 22
 // no php execution timeout for webdav
23 23
 if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
24
-	@set_time_limit(0);
24
+    @set_time_limit(0);
25 25
 }
26 26
 ignore_user_abort(true);
27 27
 
Please login to merge, or discard this patch.
lib/private/Migration/ConsoleOutput.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -37,57 +37,57 @@
 block discarded – undo
37 37
  */
38 38
 class ConsoleOutput implements IOutput {
39 39
 
40
-	/** @var OutputInterface */
41
-	private $output;
40
+    /** @var OutputInterface */
41
+    private $output;
42 42
 
43
-	/** @var ProgressBar */
44
-	private $progressBar;
43
+    /** @var ProgressBar */
44
+    private $progressBar;
45 45
 
46
-	public function __construct(OutputInterface $output) {
47
-		$this->output = $output;
48
-	}
46
+    public function __construct(OutputInterface $output) {
47
+        $this->output = $output;
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $message
52
-	 */
53
-	public function info($message) {
54
-		$this->output->writeln("<info>$message</info>");
55
-	}
50
+    /**
51
+     * @param string $message
52
+     */
53
+    public function info($message) {
54
+        $this->output->writeln("<info>$message</info>");
55
+    }
56 56
 
57
-	/**
58
-	 * @param string $message
59
-	 */
60
-	public function warning($message) {
61
-		$this->output->writeln("<comment>$message</comment>");
62
-	}
57
+    /**
58
+     * @param string $message
59
+     */
60
+    public function warning($message) {
61
+        $this->output->writeln("<comment>$message</comment>");
62
+    }
63 63
 
64
-	/**
65
-	 * @param int $max
66
-	 */
67
-	public function startProgress($max = 0) {
68
-		if (!is_null($this->progressBar)) {
69
-			$this->progressBar->finish();
70
-		}
71
-		$this->progressBar = new ProgressBar($this->output);
72
-		$this->progressBar->start($max);
73
-	}
64
+    /**
65
+     * @param int $max
66
+     */
67
+    public function startProgress($max = 0) {
68
+        if (!is_null($this->progressBar)) {
69
+            $this->progressBar->finish();
70
+        }
71
+        $this->progressBar = new ProgressBar($this->output);
72
+        $this->progressBar->start($max);
73
+    }
74 74
 
75
-	/**
76
-	 * @param int $step
77
-	 * @param string $description
78
-	 */
79
-	public function advance($step = 1, $description = '') {
80
-		if (!is_null($this->progressBar)) {
81
-			$this->progressBar = new ProgressBar($this->output);
82
-			$this->progressBar->start();
83
-		}
84
-		$this->progressBar->advance($step);
85
-	}
75
+    /**
76
+     * @param int $step
77
+     * @param string $description
78
+     */
79
+    public function advance($step = 1, $description = '') {
80
+        if (!is_null($this->progressBar)) {
81
+            $this->progressBar = new ProgressBar($this->output);
82
+            $this->progressBar->start();
83
+        }
84
+        $this->progressBar->advance($step);
85
+    }
86 86
 
87
-	public function finishProgress() {
88
-		if (is_null($this->progressBar)) {
89
-			return;
90
-		}
91
-		$this->progressBar->finish();
92
-	}
87
+    public function finishProgress() {
88
+        if (is_null($this->progressBar)) {
89
+            return;
90
+        }
91
+        $this->progressBar->finish();
92
+    }
93 93
 }
Please login to merge, or discard this patch.
apps/dav/lib/Avatars/RootCollection.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,23 +7,23 @@
 block discarded – undo
7 7
 
8 8
 class RootCollection extends AbstractPrincipalCollection {
9 9
 
10
-	/**
11
-	 * This method returns a node for a principal.
12
-	 *
13
-	 * The passed array contains principal information, and is guaranteed to
14
-	 * at least contain a uri item. Other properties may or may not be
15
-	 * supplied by the authentication backend.
16
-	 *
17
-	 * @param array $principalInfo
18
-	 * @return AvatarHome
19
-	 */
20
-	public function getChildForPrincipal(array $principalInfo) {
21
-		$avatarManager = \OC::$server->getAvatarManager();
22
-		return new AvatarHome($principalInfo, $avatarManager);
23
-	}
10
+    /**
11
+     * This method returns a node for a principal.
12
+     *
13
+     * The passed array contains principal information, and is guaranteed to
14
+     * at least contain a uri item. Other properties may or may not be
15
+     * supplied by the authentication backend.
16
+     *
17
+     * @param array $principalInfo
18
+     * @return AvatarHome
19
+     */
20
+    public function getChildForPrincipal(array $principalInfo) {
21
+        $avatarManager = \OC::$server->getAvatarManager();
22
+        return new AvatarHome($principalInfo, $avatarManager);
23
+    }
24 24
 
25
-	public function getName() {
26
-		return 'avatars';
27
-	}
25
+    public function getName() {
26
+        return 'avatars';
27
+    }
28 28
 
29 29
 }
Please login to merge, or discard this patch.
lib/private/Lockdown/LockdownManager.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -24,56 +24,56 @@
 block discarded – undo
24 24
 use OCP\Lockdown\ILockdownManager;
25 25
 
26 26
 class LockdownManager implements ILockdownManager {
27
-	/** @var ISession */
28
-	private $sessionCallback;
27
+    /** @var ISession */
28
+    private $sessionCallback;
29 29
 
30
-	private $enabled = false;
30
+    private $enabled = false;
31 31
 
32
-	/** @var array|null */
33
-	private $scope;
32
+    /** @var array|null */
33
+    private $scope;
34 34
 
35
-	/**
36
-	 * LockdownManager constructor.
37
-	 *
38
-	 * @param callable $sessionCallback we need to inject the session lazily to avoid dependency loops
39
-	 */
40
-	public function __construct(callable $sessionCallback) {
41
-		$this->sessionCallback = $sessionCallback;
42
-	}
35
+    /**
36
+     * LockdownManager constructor.
37
+     *
38
+     * @param callable $sessionCallback we need to inject the session lazily to avoid dependency loops
39
+     */
40
+    public function __construct(callable $sessionCallback) {
41
+        $this->sessionCallback = $sessionCallback;
42
+    }
43 43
 
44 44
 
45
-	public function enable() {
46
-		$this->enabled = true;
47
-	}
45
+    public function enable() {
46
+        $this->enabled = true;
47
+    }
48 48
 
49
-	/**
50
-	 * @return ISession
51
-	 */
52
-	private function getSession() {
53
-		$callback = $this->sessionCallback;
54
-		return $callback();
55
-	}
49
+    /**
50
+     * @return ISession
51
+     */
52
+    private function getSession() {
53
+        $callback = $this->sessionCallback;
54
+        return $callback();
55
+    }
56 56
 
57
-	private function getScopeAsArray() {
58
-		if (!$this->scope) {
59
-			$session = $this->getSession();
60
-			$sessionScope = $session->get('token_scope');
61
-			if ($sessionScope) {
62
-				$this->scope = $sessionScope;
63
-			}
64
-		}
65
-		return $this->scope;
66
-	}
57
+    private function getScopeAsArray() {
58
+        if (!$this->scope) {
59
+            $session = $this->getSession();
60
+            $sessionScope = $session->get('token_scope');
61
+            if ($sessionScope) {
62
+                $this->scope = $sessionScope;
63
+            }
64
+        }
65
+        return $this->scope;
66
+    }
67 67
 
68
-	public function setToken(IToken $token) {
69
-		$this->scope = $token->getScopeAsArray();
70
-		$session = $this->getSession();
71
-		$session->set('token_scope', $this->scope);
72
-		$this->enable();
73
-	}
68
+    public function setToken(IToken $token) {
69
+        $this->scope = $token->getScopeAsArray();
70
+        $session = $this->getSession();
71
+        $session->set('token_scope', $this->scope);
72
+        $this->enable();
73
+    }
74 74
 
75
-	public function canAccessFilesystem() {
76
-		$scope = $this->getScopeAsArray();
77
-		return !$scope || $scope['filesystem'];
78
-	}
75
+    public function canAccessFilesystem() {
76
+        $scope = $this->getScopeAsArray();
77
+        return !$scope || $scope['filesystem'];
78
+    }
79 79
 }
Please login to merge, or discard this patch.
lib/public/Contacts/ContactsMenu/IProvider.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@
 block discarded – undo
29 29
  */
30 30
 interface IProvider {
31 31
 
32
-	/**
33
-	 * @since 12.0
34
-	 * @param IEntry $entry
35
-	 * @return void
36
-	 */
37
-	public function process(IEntry $entry);
32
+    /**
33
+     * @since 12.0
34
+     * @param IEntry $entry
35
+     * @return void
36
+     */
37
+    public function process(IEntry $entry);
38 38
 }
Please login to merge, or discard this patch.
lib/public/Share/IShareHelper.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -32,10 +32,10 @@
 block discarded – undo
32 32
  */
33 33
 interface IShareHelper {
34 34
 
35
-	/**
36
-	 * @param Node $node
37
-	 * @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]]
38
-	 * @since 12
39
-	 */
40
-	public function getPathsForAccessList(Node $node);
35
+    /**
36
+     * @param Node $node
37
+     * @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]]
38
+     * @since 12
39
+     */
40
+    public function getPathsForAccessList(Node $node);
41 41
 }
Please login to merge, or discard this patch.
lib/private/Share20/ShareHelper.php 1 patch
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -31,187 +31,187 @@
 block discarded – undo
31 31
 
32 32
 class ShareHelper implements IShareHelper {
33 33
 
34
-	/** @var IManager */
35
-	private $shareManager;
36
-
37
-	public function __construct(IManager $shareManager) {
38
-		$this->shareManager = $shareManager;
39
-	}
40
-
41
-	/**
42
-	 * @param Node $node
43
-	 * @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]]
44
-	 */
45
-	public function getPathsForAccessList(Node $node) {
46
-		$result = [
47
-			'users' => [],
48
-			'remotes' => [],
49
-		];
50
-
51
-		$accessList = $this->shareManager->getAccessList($node, true, true);
52
-		if (!empty($accessList['users'])) {
53
-			$result['users'] = $this->getPathsForUsers($node, $accessList['users']);
54
-		}
55
-		if (!empty($accessList['remote'])) {
56
-			$result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']);
57
-		}
58
-
59
-		return $result;
60
-	}
61
-
62
-	/**
63
-	 * Sample:
64
-	 * $users = [
65
-	 *   'test1' => ['node_id' => 16, 'node_path' => '/foo'],
66
-	 *   'test2' => ['node_id' => 23, 'node_path' => '/bar'],
67
-	 *   'test3' => ['node_id' => 42, 'node_path' => '/cat'],
68
-	 *   'test4' => ['node_id' => 48, 'node_path' => '/dog'],
69
-	 * ];
70
-	 *
71
-	 * Node tree:
72
-	 * - SixTeen is the parent of TwentyThree
73
-	 * - TwentyThree is the parent of FortyTwo
74
-	 * - FortyEight does not exist
75
-	 *
76
-	 * $return = [
77
-	 *   'test1' => '/foo/TwentyThree/FortyTwo',
78
-	 *   'test2' => '/bar/FortyTwo',
79
-	 *   'test3' => '/cat',
80
-	 * ],
81
-	 *
82
-	 * @param Node $node
83
-	 * @param array[] $users
84
-	 * @return array
85
-	 */
86
-	protected function getPathsForUsers(Node $node, array $users) {
87
-		/** @var array[] $byId */
88
-		$byId = [];
89
-		/** @var array[] $results */
90
-		$results = [];
91
-
92
-		foreach ($users as $uid => $info) {
93
-			if (!isset($byId[$info['node_id']])) {
94
-				$byId[$info['node_id']] = [];
95
-			}
96
-			$byId[$info['node_id']][$uid] = $info['node_path'];
97
-		}
98
-
99
-		try {
100
-			if (isset($byId[$node->getId()])) {
101
-				foreach ($byId[$node->getId()] as $uid => $path) {
102
-					$results[$uid] = $path;
103
-				}
104
-				unset($byId[$node->getId()]);
105
-			}
106
-		} catch (NotFoundException $e) {
107
-			return $results;
108
-		} catch (InvalidPathException $e) {
109
-			return $results;
110
-		}
111
-
112
-		if (empty($byId)) {
113
-			return $results;
114
-		}
115
-
116
-		$item = $node;
117
-		$appendix = '/' . $node->getName();
118
-		while (!empty($byId)) {
119
-			try {
120
-				/** @var Node $item */
121
-				$item = $item->getParent();
122
-
123
-				if (!empty($byId[$item->getId()])) {
124
-					foreach ($byId[$item->getId()] as $uid => $path) {
125
-						$results[$uid] = $path . $appendix;
126
-					}
127
-					unset($byId[$item->getId()]);
128
-				}
129
-
130
-				$appendix = '/' . $item->getName() . $appendix;
131
-			} catch (NotFoundException $e) {
132
-				return $results;
133
-			} catch (InvalidPathException $e) {
134
-				return $results;
135
-			} catch (NotPermittedException $e) {
136
-				return $results;
137
-			}
138
-		}
139
-
140
-		return $results;
141
-	}
142
-
143
-	/**
144
-	 * Sample:
145
-	 * $remotes = [
146
-	 *   'test1' => ['node_id' => 16, 'token' => 't1'],
147
-	 *   'test2' => ['node_id' => 23, 'token' => 't2'],
148
-	 *   'test3' => ['node_id' => 42, 'token' => 't3'],
149
-	 *   'test4' => ['node_id' => 48, 'token' => 't4'],
150
-	 * ];
151
-	 *
152
-	 * Node tree:
153
-	 * - SixTeen is the parent of TwentyThree
154
-	 * - TwentyThree is the parent of FortyTwo
155
-	 * - FortyEight does not exist
156
-	 *
157
-	 * $return = [
158
-	 *   'test1' => ['token' => 't1', 'node_path' => '/SixTeen'],
159
-	 *   'test2' => ['token' => 't2', 'node_path' => '/SixTeen/TwentyThree'],
160
-	 *   'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'],
161
-	 * ],
162
-	 *
163
-	 * @param Node $node
164
-	 * @param array[] $remotes
165
-	 * @return array
166
-	 */
167
-	protected function getPathsForRemotes(Node $node, array $remotes) {
168
-		/** @var array[] $byId */
169
-		$byId = [];
170
-		/** @var array[] $results */
171
-		$results = [];
172
-
173
-		foreach ($remotes as $cloudId => $info) {
174
-			if (!isset($byId[$info['node_id']])) {
175
-				$byId[$info['node_id']] = [];
176
-			}
177
-			$byId[$info['node_id']][$cloudId] = $info['token'];
178
-		}
179
-
180
-		$item = $node;
181
-		while (!empty($byId)) {
182
-			try {
183
-				if (!empty($byId[$item->getId()])) {
184
-					$path = $this->getMountedPath($item);
185
-					foreach ($byId[$item->getId()] as $uid => $token) {
186
-						$results[$uid] = [
187
-							'node_path' => $path,
188
-							'token' => $token,
189
-						];
190
-					}
191
-					unset($byId[$item->getId()]);
192
-				}
193
-
194
-				/** @var Node $item */
195
-				$item = $item->getParent();
196
-			} catch (NotFoundException $e) {
197
-				return $results;
198
-			} catch (InvalidPathException $e) {
199
-				return $results;
200
-			} catch (NotPermittedException $e) {
201
-				return $results;
202
-			}
203
-		}
204
-
205
-		return $results;
206
-	}
207
-
208
-	/**
209
-	 * @param Node $node
210
-	 * @return string
211
-	 */
212
-	protected function getMountedPath(Node $node) {
213
-		$path = $node->getPath();
214
-		$sections = explode('/', $path, 4);
215
-		return '/' . $sections[3];
216
-	}
34
+    /** @var IManager */
35
+    private $shareManager;
36
+
37
+    public function __construct(IManager $shareManager) {
38
+        $this->shareManager = $shareManager;
39
+    }
40
+
41
+    /**
42
+     * @param Node $node
43
+     * @return array [ users => [Mapping $uid => $pathForUser], remotes => [Mapping $cloudId => $pathToMountRoot]]
44
+     */
45
+    public function getPathsForAccessList(Node $node) {
46
+        $result = [
47
+            'users' => [],
48
+            'remotes' => [],
49
+        ];
50
+
51
+        $accessList = $this->shareManager->getAccessList($node, true, true);
52
+        if (!empty($accessList['users'])) {
53
+            $result['users'] = $this->getPathsForUsers($node, $accessList['users']);
54
+        }
55
+        if (!empty($accessList['remote'])) {
56
+            $result['remotes'] = $this->getPathsForRemotes($node, $accessList['remote']);
57
+        }
58
+
59
+        return $result;
60
+    }
61
+
62
+    /**
63
+     * Sample:
64
+     * $users = [
65
+     *   'test1' => ['node_id' => 16, 'node_path' => '/foo'],
66
+     *   'test2' => ['node_id' => 23, 'node_path' => '/bar'],
67
+     *   'test3' => ['node_id' => 42, 'node_path' => '/cat'],
68
+     *   'test4' => ['node_id' => 48, 'node_path' => '/dog'],
69
+     * ];
70
+     *
71
+     * Node tree:
72
+     * - SixTeen is the parent of TwentyThree
73
+     * - TwentyThree is the parent of FortyTwo
74
+     * - FortyEight does not exist
75
+     *
76
+     * $return = [
77
+     *   'test1' => '/foo/TwentyThree/FortyTwo',
78
+     *   'test2' => '/bar/FortyTwo',
79
+     *   'test3' => '/cat',
80
+     * ],
81
+     *
82
+     * @param Node $node
83
+     * @param array[] $users
84
+     * @return array
85
+     */
86
+    protected function getPathsForUsers(Node $node, array $users) {
87
+        /** @var array[] $byId */
88
+        $byId = [];
89
+        /** @var array[] $results */
90
+        $results = [];
91
+
92
+        foreach ($users as $uid => $info) {
93
+            if (!isset($byId[$info['node_id']])) {
94
+                $byId[$info['node_id']] = [];
95
+            }
96
+            $byId[$info['node_id']][$uid] = $info['node_path'];
97
+        }
98
+
99
+        try {
100
+            if (isset($byId[$node->getId()])) {
101
+                foreach ($byId[$node->getId()] as $uid => $path) {
102
+                    $results[$uid] = $path;
103
+                }
104
+                unset($byId[$node->getId()]);
105
+            }
106
+        } catch (NotFoundException $e) {
107
+            return $results;
108
+        } catch (InvalidPathException $e) {
109
+            return $results;
110
+        }
111
+
112
+        if (empty($byId)) {
113
+            return $results;
114
+        }
115
+
116
+        $item = $node;
117
+        $appendix = '/' . $node->getName();
118
+        while (!empty($byId)) {
119
+            try {
120
+                /** @var Node $item */
121
+                $item = $item->getParent();
122
+
123
+                if (!empty($byId[$item->getId()])) {
124
+                    foreach ($byId[$item->getId()] as $uid => $path) {
125
+                        $results[$uid] = $path . $appendix;
126
+                    }
127
+                    unset($byId[$item->getId()]);
128
+                }
129
+
130
+                $appendix = '/' . $item->getName() . $appendix;
131
+            } catch (NotFoundException $e) {
132
+                return $results;
133
+            } catch (InvalidPathException $e) {
134
+                return $results;
135
+            } catch (NotPermittedException $e) {
136
+                return $results;
137
+            }
138
+        }
139
+
140
+        return $results;
141
+    }
142
+
143
+    /**
144
+     * Sample:
145
+     * $remotes = [
146
+     *   'test1' => ['node_id' => 16, 'token' => 't1'],
147
+     *   'test2' => ['node_id' => 23, 'token' => 't2'],
148
+     *   'test3' => ['node_id' => 42, 'token' => 't3'],
149
+     *   'test4' => ['node_id' => 48, 'token' => 't4'],
150
+     * ];
151
+     *
152
+     * Node tree:
153
+     * - SixTeen is the parent of TwentyThree
154
+     * - TwentyThree is the parent of FortyTwo
155
+     * - FortyEight does not exist
156
+     *
157
+     * $return = [
158
+     *   'test1' => ['token' => 't1', 'node_path' => '/SixTeen'],
159
+     *   'test2' => ['token' => 't2', 'node_path' => '/SixTeen/TwentyThree'],
160
+     *   'test3' => ['token' => 't3', 'node_path' => '/SixTeen/TwentyThree/FortyTwo'],
161
+     * ],
162
+     *
163
+     * @param Node $node
164
+     * @param array[] $remotes
165
+     * @return array
166
+     */
167
+    protected function getPathsForRemotes(Node $node, array $remotes) {
168
+        /** @var array[] $byId */
169
+        $byId = [];
170
+        /** @var array[] $results */
171
+        $results = [];
172
+
173
+        foreach ($remotes as $cloudId => $info) {
174
+            if (!isset($byId[$info['node_id']])) {
175
+                $byId[$info['node_id']] = [];
176
+            }
177
+            $byId[$info['node_id']][$cloudId] = $info['token'];
178
+        }
179
+
180
+        $item = $node;
181
+        while (!empty($byId)) {
182
+            try {
183
+                if (!empty($byId[$item->getId()])) {
184
+                    $path = $this->getMountedPath($item);
185
+                    foreach ($byId[$item->getId()] as $uid => $token) {
186
+                        $results[$uid] = [
187
+                            'node_path' => $path,
188
+                            'token' => $token,
189
+                        ];
190
+                    }
191
+                    unset($byId[$item->getId()]);
192
+                }
193
+
194
+                /** @var Node $item */
195
+                $item = $item->getParent();
196
+            } catch (NotFoundException $e) {
197
+                return $results;
198
+            } catch (InvalidPathException $e) {
199
+                return $results;
200
+            } catch (NotPermittedException $e) {
201
+                return $results;
202
+            }
203
+        }
204
+
205
+        return $results;
206
+    }
207
+
208
+    /**
209
+     * @param Node $node
210
+     * @return string
211
+     */
212
+    protected function getMountedPath(Node $node) {
213
+        $path = $node->getPath();
214
+        $sections = explode('/', $path, 4);
215
+        return '/' . $sections[3];
216
+    }
217 217
 }
Please login to merge, or discard this patch.