Completed
Push — federated-circles ( dba84e...c0d7e5 )
by Maxence
02:36
created

FederatedLink::setUniqueId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Model;
28
29
class FederatedLink implements \JsonSerializable {
30
31
32
	const STATUS_ERROR = 0;
33
	const STATUS_LINK_DOWN = 1;
34
	const STATUS_LINK_SETUP = 2;
35
	const STATUS_REQUEST_DECLINED = 4;
36
	const STATUS_REQUEST_SENT = 6;
37
	const STATUS_LINK_UP = 9;
38
39
	/** @var string */
40
	private $token;
41
42
	/** @var string */
43
	private $address;
44
45
	/** @var string */
46
	private $localAddress;
47
48
	/** @var int */
49
	private $status;
50
51
	/** @var int */
52
	private $creation;
53
54
	/** @var int */
55
	private $circleId;
56
57
	/** @var string */
58
	private $uniqueId = '';
59
60
	/** @var string */
61
	private $remoteCircleName;
62
63
	/** @var string */
64
	private $localCircleName;
65
66
67
	public function __construct() {
68
	}
69
70
71
	/**
72
	 * @param $token
73
	 *
74
	 * @return $this
75
	 */
76
	public function setToken(string $token) {
77
		$this->token = $token;
78
79
		return $this;
80
	}
81
82
	/**
83
	 * @return string
84
	 */
85
	public function getToken() {
86
		return $this->token;
87
	}
88
89
	/**
90
	 * @return string
91
	 */
92
	public function generateToken() {
93
		$token = bin2hex(openssl_random_pseudo_bytes(24));
94
		$this->setToken($token);
95
96
		return $token;
97
	}
98
99
100
	/**
101
	 * @param string $address
102
	 *
103
	 * @return FederatedLink
104
	 */
105
	public function setAddress(string $address) {
106
		$this->address = $address;
107
108
		return $this;
109
	}
110
111
	/**
112
	 * @return string
113
	 */
114
	public function getAddress() {
115
		return $this->address;
116
	}
117
118
119
	/**
120
	 * @param string $address
121
	 *
122
	 * @return FederatedLink
123
	 */
124
	public function setLocalAddress(string $address) {
125
		$this->localAddress = $address;
126
127
		return $this;
128
	}
129
130
	/**
131
	 * @return string
132
	 */
133
	public function getLocalAddress() {
134
		return $this->localAddress;
135
	}
136
137
138
	/**
139
	 * @param int $circleId
140
	 *
141
	 * @return FederatedLink
142
	 */
143
	public function setCircleId(int $circleId) {
144
		$this->circleId = $circleId;
145
146
		return $this;
147
	}
148
149
	/**
150
	 * @return int
151
	 */
152
	public function getCircleId() {
153
		return $this->circleId;
154
	}
155
156
157
	/**
158
	 * @param string $uniqueId
159
	 *
160
	 * @return FederatedLink
161
	 */
162
	public function setUniqueId(string $uniqueId) {
163
		$this->uniqueId = $uniqueId;
164
165
		return $this;
166
	}
167
168
	/**
169
	 * @return string
170
	 */
171
	public function getUniqueId() {
172
		return $this->uniqueId;
173
	}
174
175
176
	/**
177
	 * @param string $circleName
178
	 *
179
	 * @return FederatedLink
180
	 */
181
	public function setRemoteCircleName(string $circleName) {
182
		$this->remoteCircleName = $circleName;
183
184
		return $this;
185
	}
186
187
	/**
188
	 * @return string
189
	 */
190
	public function getRemoteCircleName() {
191
		return $this->remoteCircleName;
192
	}
193
194
195
	/**
196
	 * @param string $circleName
197
	 *
198
	 * @return FederatedLink
199
	 */
200
	public function setCircleName(string $circleName) {
201
		$this->localCircleName = $circleName;
202
203
		return $this;
204
	}
205
206
	/**
207
	 * @return string
208
	 */
209
	public function getCircleName() {
210
		return $this->localCircleName;
211
	}
212
213
214
	/**
215
	 * @param int $status
216
	 *
217
	 * @return FederatedLink
218
	 */
219
	public function setStatus(int $status) {
220
		$this->status = $status;
221
222
		return $this;
223
	}
224
225
	/**
226
	 * @return int
227
	 */
228
	public function getStatus() {
229
		return $this->status;
230
	}
231
232
233
	/**
234
	 * @param int $creation
235
	 *
236
	 * @return FederatedLink
237
	 */
238
	public function setCreation($creation) {
239
		if ($creation === null) {
240
			return $this;
241
		}
242
243
		$this->creation = $creation;
244
245
		return $this;
246
	}
247
248
	/**
249
	 * @return int
250
	 */
251
	public function getCreation() {
252
		return $this->creation;
253
	}
254
255
256
	public function jsonSerialize() {
257
		return array(
258
			'token'    => $this->getToken(),
259
			'address'  => $this->getAddress(),
260
			'status'   => $this->getStatus(),
261
			'creation' => $this->getCreation()
262
		);
263
	}
264
265
	public static function fromJSON($json) {
0 ignored issues
show
Unused Code introduced by
The parameter $json is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
266
	}
267
268
}