Completed
Pull Request — master (#362)
by Maxence
01:56
created

GSWrapper   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 198
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 2
dl 0
loc 198
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getToken() 0 3 1
A setToken() 0 5 1
A getEvent() 0 3 1
A setEvent() 0 5 1
A hasEvent() 0 3 1
A getInstance() 0 3 1
A setInstance() 0 5 1
A getSeverity() 0 3 1
A setSeverity() 0 5 1
A getStatus() 0 3 1
A setStatus() 0 5 1
A getCreation() 0 3 1
A setCreation() 0 5 1
A import() 0 15 1
A jsonSerialize() 0 13 1
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2017
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\Model\GlobalScale;
31
32
33
use daita\MySmallPhpTools\Traits\TArrayTools;
34
use JsonSerializable;
35
use OCA\Circles\Exceptions\JsonException;
36
use OCA\Circles\Exceptions\ModelException;
37
38
39
/**
40
 * Class GSEvent
41
 *
42
 * @package OCA\Circles\Model\GlobalScale
43
 */
44
class GSWrapper implements JsonSerializable {
45
46
47
	use TArrayTools;
48
49
50
	const STATUS_INIT = 0;
51
	const STATUS_FAILED = 1;
52
	const STATUS_DONE = 8;
53
	const STATUS_OVER = 9;
54
55
56
	/** @var string */
57
	private $token = '';
58
59
	/** @var GSEvent */
60
	private $event;
61
62
	/** @var string */
63
	private $instance = '';
64
65
	/** @var int */
66
	private $severity = GSEvent::SEVERITY_LOW;
67
68
	/** @var int */
69
	private $status = 0;
70
71
	/** @var int */
72
	private $creation;
73
74
75
	function __construct() {
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...
76
	}
77
78
79
	/**
80
	 * @return string
81
	 */
82
	public function getToken(): string {
83
		return $this->token;
84
	}
85
86
	/**
87
	 * @param string $token
88
	 *
89
	 * @return GSWrapper
90
	 */
91
	public function setToken(string $token): self {
92
		$this->token = $token;
93
94
		return $this;
95
	}
96
97
98
	/**
99
	 * @return GSEvent
100
	 */
101
	public function getEvent(): GSEvent {
102
		return $this->event;
103
	}
104
105
	/**
106
	 * @param GSEvent $event
107
	 *
108
	 * @return GSWrapper
109
	 */
110
	public function setEvent(GSEvent $event): self {
111
		$this->event = $event;
112
113
		return $this;
114
	}
115
116
	/**
117
	 * @return bool
118
	 */
119
	public function hasEvent(): bool {
120
		return ($this->event !== null);
121
	}
122
123
124
	/**
125
	 * @return string
126
	 */
127
	public function getInstance(): string {
128
		return $this->instance;
129
	}
130
131
	/**
132
	 * @param string $instance
133
	 *
134
	 * @return GSWrapper
135
	 */
136
	public function setInstance(string $instance): self {
137
		$this->instance = $instance;
138
139
		return $this;
140
	}
141
142
143
	/**
144
	 * @return int
145
	 */
146
	public function getSeverity(): int {
147
		return $this->severity;
148
	}
149
150
	/**
151
	 * @param int $severity
152
	 *
153
	 * @return GSWrapper
154
	 */
155
	public function setSeverity(int $severity): self {
156
		$this->severity = $severity;
157
158
		return $this;
159
	}
160
161
162
	/**
163
	 * @return int
164
	 */
165
	public function getStatus(): int {
166
		return $this->status;
167
	}
168
169
	/**
170
	 * @param int $status
171
	 *
172
	 * @return GSWrapper
173
	 */
174
	public function setStatus(int $status): self {
175
		$this->status = $status;
176
177
		return $this;
178
	}
179
180
181
	/**
182
	 * @return int
183
	 */
184
	public function getCreation(): int {
185
		return $this->creation;
186
	}
187
188
	/**
189
	 * @param int $creation
190
	 *
191
	 * @return GSWrapper
192
	 */
193
	public function setCreation(int $creation): self {
194
		$this->creation = $creation;
195
196
		return $this;
197
	}
198
199
200
	/**
201
	 * @param array $data
202
	 *
203
	 * @return GSWrapper
204
	 * @throws JsonException
205
	 * @throws ModelException
206
	 */
207
	public function import(array $data): self {
208
		$this->setToken($this->get('token', $data));
209
		$this->setInstance($this->get('instance', $data));
210
		$this->setSeverity($this->getInt('severity', $data, GSEvent::SEVERITY_LOW));
211
		$this->setStatus($this->getInt('status', $data, GSWrapper::STATUS_INIT));
212
213
		$event = new GSEvent();
214
		$event->importFromJson($this->get('event', $data));
215
216
		$this->setEvent($event);
217
218
		$this->setCreation($this->getInt('creation', $data));
219
220
		return $this;
221
	}
222
223
224
	/**
225
	 * @return array
226
	 */
227
	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...
228
		$arr = [
229
			'id'       => $this->getToken(),
230
			'event'    => $this->getEvent(),
231
			'severity' => $this->getSeverity(),
232
			'status'   => $this->getStatus(),
233
			'creation' => $this->getCreation()
234
		];
235
236
		$this->cleanArray($arr);
237
238
		return $arr;
239
	}
240
241
}
242
243