Passed
Push — master ( 35e3d4...f28691 )
by Morris
14:10
created

Share::getLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Björn Schießle <[email protected]>
6
 * @author Robin Appelman <[email protected]>
7
 * @author Roeland Jago Douma <[email protected]>
8
 *
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
namespace OC\Share20;
25
26
use OCP\Files\Cache\ICacheEntry;
27
use OCP\Files\File;
28
use OCP\Files\IRootFolder;
29
use OCP\Files\Node;
30
use OCP\Files\NotFoundException;
31
use OCP\IUserManager;
32
use OCP\Share\Exceptions\IllegalIDChangeException;
33
use OCP\Share\IShare;
34
35
class Share implements \OCP\Share\IShare {
36
37
	/** @var string */
38
	private $id;
39
	/** @var string */
40
	private $providerId;
41
	/** @var Node */
42
	private $node;
43
	/** @var int */
44
	private $fileId;
45
	/** @var string */
46
	private $nodeType;
47
	/** @var int */
48
	private $shareType;
49
	/** @var string */
50
	private $sharedWith;
51
	/** @var string */
52
	private $sharedWithDisplayName;
53
	/** @var string */
54
	private $sharedWithAvatar;
55
	/** @var string */
56
	private $sharedBy;
57
	/** @var string */
58
	private $shareOwner;
59
	/** @var int */
60
	private $permissions;
61
	/** @var string */
62
	private $note = '';
63
	/** @var \DateTime */
64
	private $expireDate;
65
	/** @var string */
66
	private $password;
67
	/** @var bool */
68
	private $sendPasswordByTalk = false;
69
	/** @var string */
70
	private $token;
71
	/** @var int */
72
	private $parent;
73
	/** @var string */
74
	private $target;
75
	/** @var \DateTime */
76
	private $shareTime;
77
	/** @var bool */
78
	private $mailSend;
79
	/** @var string */
80
	private $label = '';
81
82
	/** @var IRootFolder */
83
	private $rootFolder;
84
85
	/** @var IUserManager */
86
	private $userManager;
87
88
	/** @var ICacheEntry|null */
89
	private $nodeCacheEntry;
90
91
	/** @var bool */
92
	private $hideDownload = false;
93
94
	public function __construct(IRootFolder $rootFolder, IUserManager $userManager) {
95
		$this->rootFolder = $rootFolder;
96
		$this->userManager = $userManager;
97
	}
98
99
	/**
100
	 * @inheritdoc
101
	 */
102
	public function setId($id) {
103
		if (is_int($id)) {
104
			$id = (string)$id;
105
		}
106
107
		if(!is_string($id)) {
108
			throw new \InvalidArgumentException('String expected.');
109
		}
110
111
		if ($this->id !== null) {
112
			throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share');
113
		}
114
115
		$this->id = trim($id);
116
		return $this;
117
	}
118
119
	/**
120
	 * @inheritdoc
121
	 */
122
	public function getId() {
123
		return $this->id;
124
	}
125
126
	/**
127
	 * @inheritdoc
128
	 */
129
	public function getFullId() {
130
		if ($this->providerId === null || $this->id === null) {
131
			throw new \UnexpectedValueException;
132
		}
133
		return $this->providerId . ':' . $this->id;
134
	}
135
136
	/**
137
	 * @inheritdoc
138
	 */
139
	public function setProviderId($id) {
140
		if(!is_string($id)) {
141
			throw new \InvalidArgumentException('String expected.');
142
		}
143
144
		if ($this->providerId !== null) {
145
			throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share');
146
		}
147
148
		$this->providerId = trim($id);
149
		return $this;
150
	}
151
152
	/**
153
	 * @inheritdoc
154
	 */
155
	public function setNode(Node $node) {
156
		$this->fileId = null;
157
		$this->nodeType = null;
158
		$this->node = $node;
159
		return $this;
160
	}
161
162
	/**
163
	 * @inheritdoc
164
	 */
165
	public function getNode() {
166
		if ($this->node === null) {
167
168
			if ($this->shareOwner === null || $this->fileId === null) {
169
				throw new NotFoundException();
170
			}
171
172
			// for federated shares the owner can be a remote user, in this
173
			// case we use the initiator
174
			if($this->userManager->userExists($this->shareOwner)) {
175
				$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
176
			} else {
177
				$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
178
			}
179
180
			$nodes = $userFolder->getById($this->fileId);
181
			if (empty($nodes)) {
182
				throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
183
			}
184
185
			$this->node = $nodes[0];
186
		}
187
188
		return $this->node;
189
	}
190
191
	/**
192
	 * @inheritdoc
193
	 */
194
	public function setNodeId($fileId) {
195
		$this->node = null;
196
		$this->fileId = $fileId;
197
		return $this;
198
	}
199
200
	/**
201
	 * @inheritdoc
202
	 */
203
	public function getNodeId() {
204
		if ($this->fileId === null) {
205
			$this->fileId = $this->getNode()->getId();
206
		}
207
208
		return $this->fileId;
209
	}
210
211
	/**
212
	 * @inheritdoc
213
	 */
214
	public function setNodeType($type) {
215
		if ($type !== 'file' && $type !== 'folder') {
216
			throw new \InvalidArgumentException();
217
		}
218
219
		$this->nodeType = $type;
220
		return $this;
221
	}
222
223
	/**
224
	 * @inheritdoc
225
	 */
226
	public function getNodeType() {
227
		if ($this->nodeType === null) {
228
			$node = $this->getNode();
229
			$this->nodeType = $node instanceof File ? 'file' : 'folder';
230
		}
231
232
		return $this->nodeType;
233
	}
234
235
	/**
236
	 * @inheritdoc
237
	 */
238
	public function setShareType($shareType) {
239
		$this->shareType = $shareType;
240
		return $this;
241
	}
242
243
	/**
244
	 * @inheritdoc
245
	 */
246
	public function getShareType() {
247
		return $this->shareType;
248
	}
249
250
	/**
251
	 * @inheritdoc
252
	 */
253
	public function setSharedWith($sharedWith) {
254
		if (!is_string($sharedWith)) {
255
			throw new \InvalidArgumentException();
256
		}
257
		$this->sharedWith = $sharedWith;
258
		return $this;
259
	}
260
261
	/**
262
	 * @inheritdoc
263
	 */
264
	public function getSharedWith() {
265
		return $this->sharedWith;
266
	}
267
268
	/**
269
	 * @inheritdoc
270
	 */
271
	public function setSharedWithDisplayName($displayName) {
272
		if (!is_string($displayName)) {
273
			throw new \InvalidArgumentException();
274
		}
275
		$this->sharedWithDisplayName = $displayName;
276
		return $this;
277
	}
278
279
	/**
280
	 * @inheritdoc
281
	 */
282
	public function getSharedWithDisplayName() {
283
		return $this->sharedWithDisplayName;
284
	}
285
286
	/**
287
	 * @inheritdoc
288
	 */
289
	public function setSharedWithAvatar($src) {
290
		if (!is_string($src)) {
291
			throw new \InvalidArgumentException();
292
		}
293
		$this->sharedWithAvatar = $src;
294
		return $this;
295
	}
296
297
	/**
298
	 * @inheritdoc
299
	 */
300
	public function getSharedWithAvatar() {
301
		return $this->sharedWithAvatar;
302
	}
303
304
	/**
305
	 * @inheritdoc
306
	 */
307
	public function setPermissions($permissions) {
308
		//TODO checkes
309
310
		$this->permissions = $permissions;
311
		return $this;
312
	}
313
314
	/**
315
	 * @inheritdoc
316
	 */
317
	public function getPermissions() {
318
		return $this->permissions;
319
	}
320
321
	/**
322
	 * @inheritdoc
323
	 */
324
	public function setNote($note) {
325
		$this->note = $note;
326
		return $this;
327
	}
328
329
	/**
330
	 * @inheritdoc
331
	 */
332
	public function getNote() {
333
		if (is_string($this->note)) {
0 ignored issues
show
introduced by
The condition is_string($this->note) is always true.
Loading history...
334
			return $this->note;
335
		}
336
		return '';
337
	}
338
339
	/**
340
	 * @inheritdoc
341
	 */
342
	public function setLabel($label) {
343
		$this->label = $label;
344
		return $this;
345
	}
346
347
	/**
348
	 * @inheritdoc
349
	 */
350
	public function getLabel() {
351
		return $this->label;
352
	}
353
354
	/**
355
	 * @inheritdoc
356
	 */
357
	public function setExpirationDate($expireDate) {
358
		//TODO checks
359
360
		$this->expireDate = $expireDate;
361
		return $this;
362
	}
363
364
	/**
365
	 * @inheritdoc
366
	 */
367
	public function getExpirationDate() {
368
		return $this->expireDate;
369
	}
370
371
	/**
372
	 * @inheritdoc
373
	 */
374
	public function setSharedBy($sharedBy) {
375
		if (!is_string($sharedBy)) {
376
			throw new \InvalidArgumentException();
377
		}
378
		//TODO checks
379
		$this->sharedBy = $sharedBy;
380
381
		return $this;
382
	}
383
384
	/**
385
	 * @inheritdoc
386
	 */
387
	public function getSharedBy() {
388
		//TODO check if set
389
		return $this->sharedBy;
390
	}
391
392
	/**
393
	 * @inheritdoc
394
	 */
395
	public function setShareOwner($shareOwner) {
396
		if (!is_string($shareOwner)) {
397
			throw new \InvalidArgumentException();
398
		}
399
		//TODO checks
400
401
		$this->shareOwner = $shareOwner;
402
		return $this;
403
	}
404
405
	/**
406
	 * @inheritdoc
407
	 */
408
	public function getShareOwner() {
409
		//TODO check if set
410
		return $this->shareOwner;
411
	}
412
413
	/**
414
	 * @inheritdoc
415
	 */
416
	public function setPassword($password) {
417
		$this->password = $password;
418
		return $this;
419
	}
420
421
	/**
422
	 * @inheritdoc
423
	 */
424
	public function getPassword() {
425
		return $this->password;
426
	}
427
428
	/**
429
	 * @inheritdoc
430
	 */
431
	public function setSendPasswordByTalk(bool $sendPasswordByTalk) {
432
		$this->sendPasswordByTalk = $sendPasswordByTalk;
433
		return $this;
434
	}
435
436
	/**
437
	 * @inheritdoc
438
	 */
439
	public function getSendPasswordByTalk(): bool {
440
		return $this->sendPasswordByTalk;
441
	}
442
443
	/**
444
	 * @inheritdoc
445
	 */
446
	public function setToken($token) {
447
		$this->token = $token;
448
		return $this;
449
	}
450
451
	/**
452
	 * @inheritdoc
453
	 */
454
	public function getToken() {
455
		return $this->token;
456
	}
457
458
	/**
459
	 * Set the parent of this share
460
	 *
461
	 * @param int parent
0 ignored issues
show
Bug introduced by
The type OC\Share20\parent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
462
	 * @return \OCP\Share\IShare
463
	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
464
	 */
465
	public function setParent($parent) {
466
		$this->parent = $parent;
467
		return $this;
468
	}
469
470
	/**
471
	 * Get the parent of this share.
472
	 *
473
	 * @return int
474
	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
475
	 */
476
	public function getParent() {
477
		return $this->parent;
478
	}
479
480
	/**
481
	 * @inheritdoc
482
	 */
483
	public function setTarget($target) {
484
		$this->target = $target;
485
		return $this;
486
	}
487
488
	/**
489
	 * @inheritdoc
490
	 */
491
	public function getTarget() {
492
		return $this->target;
493
	}
494
495
	/**
496
	 * @inheritdoc
497
	 */
498
	public function setShareTime(\DateTime $shareTime) {
499
		$this->shareTime = $shareTime;
500
		return $this;
501
	}
502
503
	/**
504
	 * @inheritdoc
505
	 */
506
	public function getShareTime() {
507
		return $this->shareTime;
508
	}
509
510
	/**
511
	 * @inheritdoc
512
	 */
513
	public function setMailSend($mailSend) {
514
		$this->mailSend = $mailSend;
515
		return $this;
516
	}
517
518
	/**
519
	 * @inheritdoc
520
	 */
521
	public function getMailSend() {
522
		return $this->mailSend;
523
	}
524
525
	/**
526
	 * @inheritdoc
527
	 */
528
	public function setNodeCacheEntry(ICacheEntry $entry) {
529
		$this->nodeCacheEntry = $entry;
530
	}
531
532
	/**
533
	 * @inheritdoc
534
	 */
535
	public function getNodeCacheEntry() {
536
		return $this->nodeCacheEntry;
537
	}
538
539
	public function setHideDownload(bool $hide): IShare {
540
		$this->hideDownload = $hide;
541
		return $this;
542
	}
543
544
	public function getHideDownload(): bool {
545
		return $this->hideDownload;
546
	}
547
}
548