Completed
Pull Request — master (#32303)
by Victor
12:27
created

Address::getCloudId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Viktar Dubiniuk <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\FederatedFileSharing;
23
24
/**
25
 * Class Address
26
 *
27
 * @package OCA\FederatedFileSharing
28
 */
29
class Address {
30
	/**
31
	 * @var string
32
	 */
33
	protected $cloudId;
34
35
	/**
36
	 * @var string
37
	 */
38
	protected $displayName;
39
40
	/**
41
	 * Address constructor.
42
	 *
43
	 * @param string $cloudId
44
	 * @param string $displayName
45
	 */
46
	public function __construct($cloudId, $displayName = '') {
47
		$this->cloudId = $cloudId;
48
		$this->displayName = $displayName;
49
	}
50
51
	/**
52
	 * Get user federated id
53
	 *
54
	 * @return string
55
	 */
56
	public function getCloudId() {
57
		return $this->cloudId;
58
	}
59
60
	/**
61
	 * Get user id
62
	 *
63
	 * @return string
64
	 */
65
	public function getUserId() {
66
		$parts = \explode('@', $this->cloudId);
67
		return $parts[0];
68
	}
69
70
	/**
71
	 * Get user host
72
	 *
73
	 * @return string
74
	 */
75
	public function getHostName() {
76
		$parts = \explode('@', $this->cloudId);
77
		return $parts[1];
78
	}
79
80
	/**
81
	 * Get user display name, fallback to userId if it is empty
82
	 *
83
	 * @return string
84
	 */
85
	public function getDisplayName() {
86
		return ($this->displayName !== '') ? $this->displayName : $this->getUserId();
87
	}
88
}
89