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

GSWrapper::setCreation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
	/** @var string */
51
	private $token = '';
52
53
	/** @var GSEvent */
54
	private $event;
55
56
	/** @var array */
57
	private $instances = [];
58
59
	/** @var int */
60
	private $creation;
61
62
63
	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...
64
	}
65
66
67
	/**
68
	 * @return string
69
	 */
70
	public function getToken(): string {
71
		return $this->token;
72
	}
73
74
	/**
75
	 * @param string $token
76
	 *
77
	 * @return GSWrapper
78
	 */
79
	public function setToken(string $token): self {
80
		$this->token = $token;
81
82
		return $this;
83
	}
84
85
86
	/**
87
	 * @return GSEvent
88
	 */
89
	public function getEvent(): GSEvent {
90
		return $this->event;
91
	}
92
93
	/**
94
	 * @param GSEvent $event
95
	 *
96
	 * @return GSWrapper
97
	 */
98
	public function setEvent(GSEvent $event): self {
99
		$this->event = $event;
100
101
		return $this;
102
	}
103
104
	/**
105
	 * @return bool
106
	 */
107
	public function hasEvent(): bool {
108
		return ($this->event !== null);
109
	}
110
111
112
	/**
113
	 * @return array
114
	 */
115
	public function getInstances(): array {
116
		return $this->instances;
117
	}
118
119
	/**
120
	 * @param array $instances
121
	 *
122
	 * @return GSWrapper
123
	 */
124
	public function setInstances(array $instances): self {
125
		$this->instances = $instances;
126
127
		return $this;
128
	}
129
130
131
	/**
132
	 * @return int
133
	 */
134
	public function getCreation(): int {
135
		return $this->creation;
136
	}
137
138
	/**
139
	 * @param int $creation
140
	 *
141
	 * @return GSWrapper
142
	 */
143
	public function setCreation(int $creation): self {
144
		$this->creation = $creation;
145
146
		return $this;
147
	}
148
149
150
	/**
151
	 * @param array $data
152
	 *
153
	 * @return GSWrapper
154
	 * @throws JsonException
155
	 * @throws ModelException
156
	 */
157
	public function import(array $data): self {
158
		$this->setToken($this->get('id', $data));
159
160
		$event = new GSEvent();
161
		$event->importFromJson($this->get('event', $data));
162
163
		$this->setEvent($event);
164
165
		$this->setInstances($this->getArray('instances', $data));
166
		$this->setCreation($this->getInt('creation', $data));
167
168
		return $this;
169
	}
170
171
172
	/**
173
	 * @return array
174
	 */
175
	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...
176
		$arr = [
177
			'id'        => $this->getToken(),
178
			'event'     => $this->getEvent(),
179
			'instances' => $this->getInstances(),
180
			'creation'  => $this->getCreation()
181
		];
182
183
		$this->cleanArray($arr);
184
185
		return $arr;
186
	}
187
188
}
189
190