Completed
Push — federated-circles ( 47921f...25ee14 )
by Maxence
04:23
created

FederatedLink::isValid()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 2
nop 0
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 int */
40
	private $id;
41
42
	/** @var string */
43
	private $token;
44
45
	/** @var string */
46
	private $address;
47
48
	/** @var string */
49
	private $localAddress;
50
51
	/** @var int */
52
	private $status;
53
54
	/** @var int */
55
	private $creation;
56
57
	/** @var int */
58
	private $circleId;
59
60
	/** @var string */
61
	private $uniqueId = '';
62
63
	/** @var string */
64
	private $remoteCircleName;
65
66
	/** @var string */
67
	private $localCircleName;
68
69
70
	public function __construct() {
71
	}
72
73
74
	/**
75
	 * @param int $id
76
	 *
77
	 * @return FederatedLink
78
	 */
79
	public function setId(int $id) {
80
		$this->id = $id;
81
82
		return $this;
83
	}
84
85
	/**
86
	 * @return int
87
	 */
88
	public function getId() {
89
		return $this->id;
90
	}
91
92
93
	/**
94
	 * @param $token
95
	 *
96
	 * @return $this
97
	 */
98
	public function setToken(string $token) {
99
		$this->token = $token;
100
101
		return $this;
102
	}
103
104
	/**
105
	 * @return string
106
	 */
107
	public function getToken() {
108
		return $this->token;
109
	}
110
111
	/**
112
	 * @return string
113
	 */
114
	public function generateToken() {
115
		$token = bin2hex(openssl_random_pseudo_bytes(24));
116
		$this->setToken($token);
117
118
		return $token;
119
	}
120
121
122
	/**
123
	 * @param string $address
124
	 *
125
	 * @return FederatedLink
126
	 */
127
	public function setAddress(string $address) {
128
		$this->address = $address;
129
130
		return $this;
131
	}
132
133
	/**
134
	 * @return string
135
	 */
136
	public function getAddress() {
137
		return $this->address;
138
	}
139
140
141
	/**
142
	 * @param string $address
143
	 *
144
	 * @return FederatedLink
145
	 */
146
	public function setLocalAddress(string $address) {
147
		$this->localAddress = $address;
148
149
		return $this;
150
	}
151
152
	/**
153
	 * @return string
154
	 */
155
	public function getLocalAddress() {
156
		return $this->localAddress;
157
	}
158
159
160
	/**
161
	 * @param int $circleId
162
	 *
163
	 * @return FederatedLink
164
	 */
165
	public function setCircleId(int $circleId) {
166
		$this->circleId = $circleId;
167
168
		return $this;
169
	}
170
171
	/**
172
	 * @return int
173
	 */
174
	public function getCircleId() {
175
		return $this->circleId;
176
	}
177
178
179
	/**
180
	 * @param string $uniqueId
181
	 *
182
	 * @return FederatedLink
183
	 */
184
	public function setUniqueId(string $uniqueId) {
185
		$this->uniqueId = $uniqueId;
186
187
		return $this;
188
	}
189
190
	/**
191
	 * @return string
192
	 */
193
	public function getUniqueId() {
194
		return $this->uniqueId;
195
	}
196
197
198
	/**
199
	 * @param string $circleName
200
	 *
201
	 * @return FederatedLink
202
	 */
203
	public function setRemoteCircleName(string $circleName) {
204
		$this->remoteCircleName = $circleName;
205
206
		return $this;
207
	}
208
209
	/**
210
	 * @return string
211
	 */
212
	public function getRemoteCircleName() {
213
		return $this->remoteCircleName;
214
	}
215
216
217
	/**
218
	 * @param string $circleName
219
	 *
220
	 * @return FederatedLink
221
	 */
222
	public function setCircleName(string $circleName) {
223
		$this->localCircleName = $circleName;
224
225
		return $this;
226
	}
227
228
	/**
229
	 * @return string
230
	 */
231
	public function getCircleName() {
232
		return $this->localCircleName;
233
	}
234
235
236
	/**
237
	 * @param int $status
238
	 *
239
	 * @return FederatedLink
240
	 */
241
	public function setStatus(int $status) {
242
		$this->status = $status;
243
244
		return $this;
245
	}
246
247
	/**
248
	 * @return int
249
	 */
250
	public function getStatus() {
251
		return $this->status;
252
	}
253
254
255
	/**
256
	 * @param int $creation
257
	 *
258
	 * @return FederatedLink
259
	 */
260
	public function setCreation($creation) {
261
		if ($creation === null) {
262
			return $this;
263
		}
264
265
		$this->creation = $creation;
266
267
		return $this;
268
	}
269
270
	/**
271
	 * @return int
272
	 */
273
	public function getCreation() {
274
		return $this->creation;
275
	}
276
277
278
	public function isValid() {
279
280
		if ($this->getStatus() === FederatedLink::STATUS_REQUEST_SENT
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $this->getStatus(...edLink::STATUS_LINK_UP;.
Loading history...
281
			|| $this->getStatus() === FederatedLink::STATUS_LINK_UP
282
		) {
283
			return true;
284
		}
285
286
		return false;
287
	}
288
289
	public function jsonSerialize() {
290
		return array(
291
			'token'    => $this->getToken(),
292
			'address'  => $this->getAddress(),
293
			'status'   => $this->getStatus(),
294
			'creation' => $this->getCreation()
295
		);
296
	}
297
298
	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...
299
	}
300
301
}