Completed
Push — master ( 347a51...ad246f )
by Maxence
02:23
created

Tick::getInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
nc 1
cc 1
nop 2
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * FullTextSearch - Full text search framework for Nextcloud
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCA\FullTextSearch\Model;
32
33
34
use daita\MySmallPhpTools\Traits\TArrayTools;
35
36
/**
37
 * Class Tick
38
 *
39
 * @package OCA\FullTextSearch\Model
40
 */
41
class Tick {
42
43
44
	use TArrayTools;
45
46
47
	/** @var int */
48
	private $id;
49
50
	/** @var string */
51
	private $source;
52
53
	/** @var array */
54
	protected $data;
55
56
	/** @var int */
57
	private $tick;
58
59
	/** @var int */
60
	private $firstTick;
61
62
	/** @var string */
63
	private $status;
64
65
	/** @var string */
66
	private $action = '';
67
68
69
	/**
70
	 * Tick constructor.
71
	 *
72
	 * @param string $source
73
	 * @param int $id
74
	 */
75
	public function __construct(string $source, int $id = 0) {
76
		$this->source = $source;
77
		$this->id = $id;
78
	}
79
80
81
	/**
82
	 * @return int
83
	 */
84
	public function getId(): int {
85
		return $this->id;
86
	}
87
88
	/**
89
	 * @param int $id
90
	 *
91
	 * @return $this
92
	 */
93
	public function setId(int $id): Tick {
94
		$this->id = $id;
95
96
		return $this;
97
	}
98
99
100
	/**
101
	 * @return string
102
	 */
103
	public function getSource(): string {
104
		return $this->source;
105
	}
106
107
108
	/**
109
	 * @return array
110
	 */
111
	public function getData(): array {
112
		return $this->data;
113
	}
114
115
	/**
116
	 * @param array $data
117
	 *
118
	 * @return $this
119
	 */
120
	public function setData(array $data): Tick {
121
		$this->data = $data;
122
123
		return $this;
124
	}
125
126
127
	/**
128
	 * @return int
129
	 */
130
	public function getTick(): int {
131
		return $this->tick;
132
	}
133
134
	/**
135
	 * @param int $tick
136
	 *
137
	 * @return $this
138
	 */
139
	public function setTick(int $tick = 0): Tick {
140
		if ($tick === 0) {
141
			$tick = time();
142
		}
143
144
		$this->tick = $tick;
145
146
		return $this;
147
	}
148
149
150
	/**
151
	 * @return int
152
	 */
153
	public function getFirstTick(): int {
154
		return $this->firstTick;
155
	}
156
157
	/**
158
	 * @param int $tick
159
	 *
160
	 * @return $this
161
	 */
162
	public function setFirstTick(int $tick = 0): Tick {
163
		if ($tick === 0) {
164
			$tick = time();
165
		}
166
167
		$this->firstTick = $tick;
168
169
		return $this;
170
	}
171
172
173
	/**
174
	 * @return string
175
	 */
176
	public function getStatus(): string {
177
		return $this->status;
178
	}
179
180
	/**
181
	 * @param string $status
182
	 *
183
	 * @return $this
184
	 */
185
	public function setStatus(string $status): Tick {
186
		$this->status = $status;
187
188
		return $this;
189
	}
190
191
192
	/**
193
	 * @return string
194
	 */
195
	public function getAction(): string {
196
		return $this->action;
197
	}
198
199
	/**
200
	 * @param string $action
201
	 *
202
	 * @return $this
203
	 */
204
	public function setAction(string $action): Tick {
205
		$this->action = $action;
206
207
		return $this;
208
	}
209
210
211
	/**
212
	 * @param string $info
213
	 * @param string $value
214
	 *
215
	 * @return $this
216
	 */
217
	public function setInfo(string $info, string $value): Tick {
218
		$this->data[$info] = $value;
219
220
		return $this;
221
	}
222
223
	/**
224
	 * @param string $info
225
	 * @param int $value
226
	 *
227
	 * @return $this
228
	 */
229
	public function setInfoInt(string $info, int $value): Tick {
230
		$this->data[$info] = $value;
231
232
		return $this;
233
	}
234
235
	/**
236
	 * @param string $info
237
	 * @param float $value
238
	 *
239
	 * @return $this
240
	 */
241
	public function setInfoFloat(string $info, float $value): Tick {
242
		$this->data[$info] = $value;
243
244
		return $this;
245
	}
246
247
	/**
248
	 * @param string $info
249
	 */
250
	public function unsetInfo(string $info) {
251
		unset($this->data[$info]);
252
	}
253
254
	/**
255
	 * @param string $info
256
	 * @param string $default
257
	 *
258
	 * @return string
259
	 */
260
	public function getInfo(string $info, string $default = ''): string {
261
		return $this->get($info, $this->data, $default);
262
	}
263
264
265
	/**
266
	 * @param string $info
267
	 * @param int $default
268
	 *
269
	 * @return int
270
	 */
271
	public function getInfoInt(string $info, int $default = 0): int {
272
		return $this->getInt($info, $this->data, $default);
273
	}
274
275
	/**
276
	 * @param string $info
277
	 * @param float $default
0 ignored issues
show
Documentation introduced by
Should the type for parameter $default not be integer|double?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
278
	 *
279
	 * @return float
280
	 */
281
	public function getInfoFloat(string $info, float $default = 0): float {
282
		return $this->getFloat($info, $this->data, $default);
283
	}
284
285
}
286
287