Completed
Pull Request — master (#362)
by Maxence
02:16
created

GSShare::getOwner()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2017
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\Model\GlobalScale;
31
32
33
use daita\MySmallPhpTools\Traits\TArrayTools;
34
use JsonSerializable;
35
36
37
/**
38
 * Class GSShare
39
 *
40
 * @package OCA\Circles\Model\GlobalScale
41
 */
42
class GSShare implements JsonSerializable {
43
44
45
	use TArrayTools;
46
47
48
	/** @var int */
49
	private $id = 0;
50
51
	/** @var string */
52
	private $circleId = '';
53
54
	/** @var string */
55
	private $defaultMountPoint = '';
56
57
	/** @var string */
58
	private $mountPoint = '';
59
60
	/** @var int */
61
	private $parent = -1;
62
63
	/** @var string */
64
	private $owner = '';
65
66
	/** @var string */
67
	private $instance = '';
68
69
	/** @var string */
70
	private $token = '';
71
72
	/** @var string */
73
	private $password = '';
74
75
76
	/**
77
	 * GSShare constructor.
78
	 *
79
	 * @param string $circleId
80
	 * @param string $token
81
	 */
82
	public function __construct(string $circleId = '', string $token = '') {
83
		$this->circleId = $circleId;
84
		$this->token = $token;
85
	}
86
87
88
	/**
89
	 * @return int
90
	 */
91
	public function getId(): int {
92
		return $this->id;
93
	}
94
95
	public function setId(int $id): self {
96
		$this->id = $id;
97
98
		return $this;
99
	}
100
101
102
	/**
103
	 *
104
	 * @return string
105
	 */
106
	public function getCircleId(): string {
107
		return $this->circleId;
108
	}
109
110
	/**
111
	 * @param string $circleId
112
	 *
113
	 * @return GSShare
114
	 */
115
	public function setCircleId(string $circleId): self {
116
		$this->circleId = $circleId;
117
118
		return $this;
119
	}
120
121
122
	/**
123
	 * @return string
124
	 */
125
	public function getDefaultMountPoint(): string {
126
		return $this->defaultMountPoint;
127
	}
128
129
	/**
130
	 * @param string $mountPoint
131
	 *
132
	 * @return GSShare
133
	 */
134
	public function setDefaultMountPoint(string $mountPoint): self {
135
		if ($this->getMountPoint() === '') {
136
			$this->setMountPoint($mountPoint);
137
		}
138
139
		$this->defaultMountPoint = $mountPoint;
140
141
		return $this;
142
	}
143
144
145
	/**
146
	 * @param string $userId
147
	 *
148
	 * @return string
149
	 */
150
	public function getMountPoint(string $userId = ''): string {
151
		if ($userId === '') {
152
			return $this->mountPoint;
153
		}
154
155
		return '/' . $userId . '/files/' . ltrim($this->mountPoint, '/');
156
	}
157
158
	/**
159
	 * @param string $mountPoint
160
	 *
161
	 * @return GSShare
162
	 */
163
	public function setMountPoint(string $mountPoint): self {
164
		$this->mountPoint = $mountPoint;
165
166
		return $this;
167
	}
168
169
170
	/**
171
	 * @return int
172
	 */
173
	public function getParent(): int {
174
		return $this->parent;
175
	}
176
177
	/**
178
	 * @param int $parent
179
	 *
180
	 * @return GSShare
181
	 */
182
	public function setParent(int $parent): self {
183
		$this->parent = $parent;
184
185
		return $this;
186
	}
187
188
189
	/**
190
	 * @return string
191
	 */
192
	public function getOwner(): string {
193
		return $this->owner;
194
	}
195
196
	/**
197
	 * @param string $owner
198
	 *
199
	 * @return GSShare
200
	 */
201
	public function setOwner(string $owner): self {
202
		$this->owner = $owner;
203
204
		return $this;
205
	}
206
207
208
	/**
209
	 * @return string
210
	 */
211
	public function getInstance(): string {
212
		return $this->instance;
213
	}
214
215
	/**
216
	 * @param string $instance
217
	 *
218
	 * @return GSShare
219
	 */
220
	public function setInstance(string $instance): self {
221
		$this->instance = $instance;
222
223
		return $this;
224
	}
225
226
227
	/**
228
	 * @return string
229
	 */
230
	public function getToken(): string {
231
		return $this->token;
232
	}
233
234
235
	/**
236
	 * @param string $token
237
	 *
238
	 * @return GSShare
239
	 */
240
	public function setToken(string $token): self {
241
		$this->token = $token;
242
243
		return $this;
244
	}
245
246
247
	/**
248
	 * @return string
249
	 */
250
	public function getPassword(): string {
251
		return $this->password;
252
	}
253
254
	/**
255
	 * @param string $password
256
	 *
257
	 * @return GSShare
258
	 */
259
	public function setPassword(string $password): self {
260
		$this->password = $password;
261
262
		return $this;
263
	}
264
265
266
	/**
267
	 * @param array $data
268
	 *
269
	 * @return GSShare
270
	 */
271
	public function importFromDatabase(array $data): self {
272
		$this->setId($this->getInt('id', $data));
273
		$this->setCircleId($this->get('circle_id', $data));
274
		$this->setOwner($this->get('owner', $data));
275
		$this->setInstance($this->get('instance', $data));
276
		$this->setToken($this->get('token', $data));
277
		$this->setParent($this->getInt('parent', $data));
278
		$this->setDefaultMountPoint($this->get('mountpoint', $data));
279
280
		return $this;
281
	}
282
283
284
	/**
285
	 * @param string $userId
286
	 * @param string $protocol
287
	 *
288
	 * @return array
289
	 */
290
	public function toMount(string $userId, string $protocol = 'https'): array {
291
		return [
292
			'owner'       => $this->getOwner(),
293
			'remote'      => $protocol . '://' . $this->getInstance(),
294
			'token'       => $this->getToken(),
295
			'share_token' => $this->getToken(),
296
			'password'    => $this->getPassword(),
297
			'mountpoint'  => $this->getMountPoint($userId)
298
		];
299
	}
300
301
302
	/**
303
	 * @return array
304
	 */
305
	function jsonSerialize(): array {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
306
		return [
307
			'id'                => $this->getId(),
308
			'defaultMountPoint' => $this->getDefaultMountPoint(),
309
			'mountPoint'        => $this->getMountPoint(),
310
			'parent'            => $this->getParent(),
311
			'owner'             => $this->getOwner(),
312
			'instance'          => $this->getInstance(),
313
			'token'             => $this->getToken(),
314
			'password'          => $this->getPassword()
315
		];
316
	}
317
318
}
319
320