Completed
Push — master ( 6b77ae...733b21 )
by Maxence
02:27
created

Index::getStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * FullTextSearch - Full text search framework for Nextcloud
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 2018
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\FullTextSearch\Model;
28
29
class Index implements \JsonSerializable {
30
31
	const INDEX_OK = 1;
32
	const INDEX_IGNORE = 2;
33
34
	const INDEX_META = 4;
35
	const INDEX_CONTENT = 8;
36
	const INDEX_FULL = 12;
37
	const INDEX_REMOVE = 16;
38
39
	const INDEX_DONE = 32;
40
	const INDEX_FAILED = 64;
41
42
	const ERROR_FAILED = 1;
43
	const ERROR_FAILED2 = 2;
44
	const ERROR_FAILED3 = 4;
45
46
47
	/** @var string */
48
	private $providerId;
49
50
	/** @var string */
51
	private $documentId;
52
53
	/** @var string */
54
	private $ownerId = '';
55
56
	/** @var int */
57
	private $status = 0;
58
59
	/** @var array */
60
	private $options = [];
61
62
	/** @var int */
63
	private $err = 0;
64
65
	/** @var string */
66
	private $message;
67
68
	/** @var int */
69
	private $lastIndex = 0;
70
71
72
	public function __construct($providerId, $documentId) {
73
		$this->providerId = $providerId;
74
		$this->documentId = $documentId;
75
	}
76
77
78
	/**
79
	 * @return string
80
	 */
81
	public function getProviderId() {
82
		return $this->providerId;
83
	}
84
85
	/**
86
	 * @return string
87
	 */
88
	public function getDocumentId() {
89
		return $this->documentId;
90
	}
91
92
93
	/**
94
	 * @param string $ownerId
95
	 *
96
	 * @return $this
97
	 */
98
	public function setOwnerId($ownerId) {
99
		$this->ownerId = $ownerId;
100
101
		return $this;
102
	}
103
104
	/**
105
	 * @return string
106
	 */
107
	public function getOwnerId() {
108
		return $this->ownerId;
109
	}
110
111
112
	/**
113
	 * @param int $status
114
	 * @param bool $reset
115
	 *
116
	 * @return $this
117
	 */
118
	public function setStatus($status, $reset = false) {
119
		if ($reset === true) {
120
			$this->status = $status;
121
		} else if (!$this->isStatus($status)) {
122
			$this->status += $status;
123
		}
124
125
		return $this;
126
	}
127
128
	/**
129
	 * @return int
130
	 */
131
	public function getStatus() {
132
		return $this->status;
133
	}
134
135
	/**
136
	 * @param int $status
137
	 *
138
	 * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
139
	 */
140
	public function isStatus($status) {
141
		return ((int)$status & $this->getStatus());
142
	}
143
144
	/**
145
	 * @param int $status
146
	 */
147
	public function unsetStatus($status) {
148
		if (!$this->isStatus($status)) {
149
			return;
150
		}
151
152
		$this->status -= $status;
153
	}
154
155
156
	/**
157
	 * @param array $options
158
	 *
159
	 * @return $this
160
	 */
161
	public function setOptions($options) {
162
		$this->options = $options;
163
164
		return $this;
165
	}
166
167
	/**
168
	 * @return array
169
	 */
170
	public function getOptions() {
171
		return $this->options;
172
	}
173
174
175
	/**
176
	 * @param int $err
177
	 *
178
	 * @return $this
179
	 */
180
	public function setError($err) {
181
		$this->err = $err;
182
183
		return $this;
184
	}
185
186
	/**
187
	 * @return int
188
	 */
189
	public function getError() {
190
		return $this->err;
191
	}
192
193
	/**
194
	 * @return $this
195
	 */
196
	public function incrementError() {
197
		$this->err++;
198
199
		return $this;
200
	}
201
202
203
	/**
204
	 * @return string
205
	 */
206
	public function getMessage() {
207
		return $this->message;
208
	}
209
210
	/**
211
	 * @param string $message
212
	 *
213
	 * @return Index
214
	 */
215
	public function setMessage($message) {
216
		$this->message = substr($message, 0, 3800);
217
218
		return $this;
219
	}
220
221
222
	/**
223
	 * @param int $lastIndex
224
	 *
225
	 * @return $this
226
	 */
227
	public function setLastIndex($lastIndex = -1) {
228
		if ($lastIndex === -1) {
229
			$lastIndex = time();
230
		}
231
232
		$this->lastIndex = $lastIndex;
233
234
		return $this;
235
	}
236
237
	/**
238
	 * @return int
239
	 */
240
	public function getLastIndex() {
241
		return $this->lastIndex;
242
	}
243
244
245
	/**
246
	 * @return array<string,string|integer>
247
	 */
248
	public function jsonSerialize() {
249
		return [
250
			'ownerId'    => $this->getOwnerId(),
251
			'providerId' => $this->getProviderId(),
252
			'documentId' => $this->getDocumentId(),
253
			'lastIndex'  => $this->getLastIndex(),
254
			'status'     => (int)$this->getStatus()
255
		];
256
	}
257
258
}