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

RemoteEvent::getSeverity()   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
2
3
declare(strict_types=1);
4
5
6
/**
7
 * Circles - Bring cloud-users closer together.
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later. See the COPYING file.
11
 *
12
 * @author Maxence Lange <[email protected]>
13
 * @copyright 2021
14
 * @license GNU AGPL version 3 or any later version
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 *
29
 */
30
31
32
namespace OCA\Circles\Model\Remote;
33
34
35
use daita\MySmallPhpTools\Model\SimpleDataStore;
36
use daita\MySmallPhpTools\Traits\TArrayTools;
37
use JsonSerializable;
38
use OCA\Circles\Model\Circle;
39
use OCA\Circles\Model\Member;
40
41
42
/**
43
 * Class RemoteEvent
44
 *
45
 * @package OCA\Circles\Model\Remote
46
 */
47
class RemoteEvent implements JsonSerializable {
48
49
50
	const SEVERITY_LOW = 1;
51
	const SEVERITY_HIGH = 3;
52
53
54
	use TArrayTools;
55
56
57
	/** @var string */
58
	private $class;
59
60
	/** @var string */
61
	private $source = '';
62
63
	/** @var Circle */
64
	private $circle;
65
66
	/** @var Member */
67
	private $member;
68
69
	/** @var SimpleDataStore */
70
	private $data;
71
72
	/** @var int */
73
	private $severity = self::SEVERITY_LOW;
74
75
	/** @var SimpleDataStore */
76
	private $result;
77
78
	/** @var bool */
79
	private $local;
80
81
	/** @var bool */
82
	private $async = false;
83
84
85
	/** @var string */
86
	private $wrapperToken = '';
87
88
	/** @var bool */
89
	private $verifiedViewer = false;
90
91
92
	/**
93
	 * RemoteEvent constructor.
94
	 *
95
	 * @param string $class
96
	 * @param bool $local
97
	 */
98 View Code Duplication
	function __construct(string $class = '', bool $local = false) {
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
		$this->class = $class;
100
		$this->local = $local;
101
		$this->data = new SimpleDataStore();
102
		$this->result = new SimpleDataStore();
103
	}
104
105
106
	/**
107
	 * @return string
108
	 */
109
	public function getClass(): string {
110
		return $this->class;
111
	}
112
113
	/**
114
	 * @param mixed $class
115
	 *
116
	 * @return self
117
	 */
118
	public function setClass($class): self {
119
		$this->class = $class;
120
121
		return $this;
122
	}
123
124
125
	/**
126
	 * @return string
127
	 */
128
	public function getSource(): string {
129
		return $this->source;
130
	}
131
132
	/**
133
	 * @param string $source
134
	 *
135
	 * @return self
136
	 */
137
	public function setSource(string $source): self {
138
		$this->source = $source;
139
140
		if ($this->hasMember() && $this->member->getInstance() === '') {
141
			$this->member->setInstance($source);
142
		}
143
144
//		if ($this->hasCircle()
145
//			&& $this->getCircle()
146
//					->hasViewer()
147
//			&& $this->getCircle()
148
//					->getViewer()
149
//					->getInstance() === '') {
150
//			$this->getCircle()
151
//				 ->getViewer()
152
//				 ->setInstance($source);
153
//		}
154
155
		return $this;
156
	}
157
158
159
	/**
160
	 * @return bool
161
	 */
162
	public function isLocal(): bool {
163
		return $this->local;
164
	}
165
166
	/**
167
	 * @param bool $local
168
	 *
169
	 * @return self
170
	 */
171
	public function setLocal(bool $local): self {
172
		$this->local = $local;
173
174
		return $this;
175
	}
176
177
178
	/**
179
	 * @return bool
180
	 */
181
	public function isAsync(): bool {
182
		return $this->async;
183
	}
184
185
	/**
186
	 * @param bool $async
187
	 *
188
	 * @return self
189
	 */
190
	public function setAsync(bool $async): self {
191
		$this->async = $async;
192
193
		return $this;
194
	}
195
196
197
	/**
198
	 * @param bool $verifiedViewer
199
	 */
200
	public function setVerifiedViewer(bool $verifiedViewer): void {
201
		$this->verifiedViewer = $verifiedViewer;
202
	}
203
204
	/**
205
	 * @return bool
206
	 */
207
	public function isVerifiedViewer(): bool {
208
		return $this->verifiedViewer;
209
	}
210
211
212
	/**
213
	 * @param string $wrapperToken
214
	 *
215
	 * @return RemoteEvent
216
	 */
217
	public function setWrapperToken(string $wrapperToken): self {
218
		$this->wrapperToken = $wrapperToken;
219
220
		return $this;
221
	}
222
223
	/**
224
	 * @return string
225
	 */
226
	public function getWrapperToken(): string {
227
		return $this->wrapperToken;
228
	}
229
230
231
232
233
234
	/**
235
	 * @return bool
236
	 */
237
	public function hasCircle(): bool {
238
		return ($this->circle !== null);
239
	}
240
241
	/**
242
	 * @param Circle $circle
243
	 *
244
	 * @return self
245
	 */
246
	public function setCircle(Circle $circle): self {
247
		$this->circle = $circle;
248
249
		return $this;
250
	}
251
252
	/**
253
	 * @return Circle
254
	 */
255
	public function getCircle(): Circle {
256
		return $this->circle;
257
	}
258
259
260
	/**
261
	 * @return Member
262
	 */
263
	public function getMember(): Member {
264
		return $this->member;
265
	}
266
267
	/**
268
	 * @param Member $member
269
	 *
270
	 * @return self
271
	 */
272
	public function setMember(Member $member): self {
273
		$this->member = $member;
274
275
		return $this;
276
	}
277
278
	/**
279
	 * @return bool
280
	 */
281
	public function hasMember(): bool {
282
		return ($this->member !== null);
283
	}
284
285
286
	/**
287
	 * @param SimpleDataStore $data
288
	 *
289
	 * @return self
290
	 */
291
	public function setData(SimpleDataStore $data): self {
292
		$this->data = $data;
293
294
		return $this;
295
	}
296
297
	/**
298
	 * @return SimpleDataStore
299
	 */
300
	public function getData(): SimpleDataStore {
301
		return $this->data;
302
	}
303
304
305
	/**
306
	 * @return int
307
	 */
308
	public function getSeverity(): int {
309
		return $this->severity;
310
	}
311
312
	/**
313
	 * @param int $severity
314
	 *
315
	 * @return self
316
	 */
317
	public function setSeverity(int $severity): self {
318
		$this->severity = $severity;
319
320
		return $this;
321
	}
322
323
324
	/**
325
	 * @return SimpleDataStore
326
	 */
327
	public function getResult(): SimpleDataStore {
328
		return $this->result;
329
	}
330
331
	/**
332
	 * @param SimpleDataStore $result
333
	 *
334
	 * @return self
335
	 */
336
	public function setResult(SimpleDataStore $result): self {
337
		$this->result = $result;
338
339
		return $this;
340
	}
341
342
343
	/**
344
	 * @param array $data
345
	 *
346
	 * @return self
347
	 */
348
	public function import(array $data): self {
349
		$this->setClass($this->get('class', $data));
350
		$this->setSeverity($this->getInt('severity', $data));
351
		$this->setData(new SimpleDataStore($this->getArray('data', $data)));
352
		$this->setResult(new SimpleDataStore($this->getArray('result', $data)));
353
		$this->setSource($this->get('source', $data));
354
		$this->setAsync($this->getBool('async', $data));
355
356
		if (array_key_exists('circle', $data)) {
357
			$circle = new Circle();
358
			$circle->import($this->getArray('circle', $data));
359
			$this->setCircle($circle);
360
		}
361
362
		if (array_key_exists('member', $data)) {
363
			$member = new Member();
364
			$member->import($this->getArray('member', $data));
365
			$this->setMember($member);
366
		}
367
368
		return $this;
369
	}
370
371
372
	/**
373
	 * @return array
374
	 */
375
	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...
376
		$arr = [
377
			'class'    => $this->getClass(),
378
			'severity' => $this->getSeverity(),
379
			'data'     => $this->getData(),
380
			'result'   => $this->getResult(),
381
			'source'   => $this->getSource(),
382
			'async'    => $this->isAsync()
383
		];
384
385
		if ($this->hasCircle()) {
386
			$arr['circle'] = $this->getCircle();
387
		}
388
		if ($this->hasMember()) {
389
			$arr['member'] = $this->getMember();
390
		}
391
392
		return $arr;
393
	}
394
395
396
}
397
398