Passed
Push — master ( de25e4...1e5fad )
by Morris
10:17 queued 12s
created

SearchRequestSimpleQuery::addValueArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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 OC\FullTextSearch\Model;
32
33
34
use JsonSerializable;
35
use OCP\FullTextSearch\Model\ISearchRequestSimpleQuery;
36
37
38
/**
39
 * @since 17.0.0
40
 *
41
 * Class SearchRequestSimpleQuery
42
 *
43
 * @package OC\FullTextSearch\Model
44
 */
45
final class SearchRequestSimpleQuery implements ISearchRequestSimpleQuery, JsonSerializable {
46
47
48
	/** @var int */
49
	private $type = 0;
50
51
	/** @var string */
52
	private $field = '';
53
54
	/** @var array */
55
	private $values = [];
56
57
58
	/**
59
	 * SearchRequestQuery constructor.
60
	 *
61
	 * @param $type
62
	 * @param $field
63
	 *
64
	 * @since 17.0.0
65
	 */
66
	public function __construct(string $field, int $type) {
67
		$this->field = $field;
68
		$this->type = $type;
69
	}
70
71
72
	/**
73
	 * Get the compare type of the query
74
	 *
75
	 * @return int
76
	 * @since 17.0.0
77
	 */
78
	public function getType(): int {
79
		return $this->type;
80
	}
81
82
83
	/**
84
	 * Get the field to apply query
85
	 *
86
	 * @return string
87
	 * @since 17.0.0
88
	 */
89
	public function getField(): string {
90
		return $this->field;
91
	}
92
93
	/**
94
	 * Set the field to apply query
95
	 *
96
	 * @param string $field
97
	 *
98
	 * @return ISearchRequestSimpleQuery
99
	 * @since 17.0.0
100
	 */
101
	public function setField(string $field): ISearchRequestSimpleQuery {
102
		$this->field = $field;
103
104
		return $this;
105
	}
106
107
108
	/**
109
	 * Get the value to compare (string)
110
	 *
111
	 * @return array
112
	 * @since 17.0.0
113
	 */
114
	public function getValues(): array {
115
		return $this->values;
116
	}
117
118
119
	/**
120
	 * Add value to compare (string)
121
	 *
122
	 * @param string $value
123
	 *
124
	 * @return ISearchRequestSimpleQuery
125
	 * @since 17.0.0
126
	 */
127
	public function addValue(string $value): ISearchRequestSimpleQuery {
128
		$this->values[] = $value;
129
130
		return $this;
131
	}
132
133
	/**
134
	 * Add value to compare (int)
135
	 *
136
	 * @param int $value
137
	 *
138
	 * @return ISearchRequestSimpleQuery
139
	 * @since 17.0.0
140
	 */
141
	public function addValueInt(int $value): ISearchRequestSimpleQuery {
142
		$this->values[] = $value;
143
144
		return $this;
145
	}
146
147
	/**
148
	 * Add value to compare (array)
149
	 *
150
	 * @param array $value
151
	 *
152
	 * @return ISearchRequestSimpleQuery
153
	 * @since 17.0.0
154
	 */
155
	public function addValueArray(array $value): ISearchRequestSimpleQuery {
156
		$this->values[] = $value;
157
158
		return $this;
159
	}
160
161
	/**
162
	 * Add value to compare (bool)
163
	 *
164
	 * @param bool $value
165
	 *
166
	 * @return ISearchRequestSimpleQuery
167
	 * @since 17.0.0
168
	 */
169
	public function addValueBool(bool $value): ISearchRequestSimpleQuery {
170
		$this->values[] = $value;
171
172
		return $this;
173
	}
174
175
176
	/**
177
	 * @return array|mixed
178
	 * @since 17.0.0
179
	 */
180
	public function jsonSerialize() {
181
		return [
182
			'type'   => $this->getType(),
183
			'field'  => $this->getField(),
184
			'values' => $this->getValues()
185
		];
186
	}
187
188
}
189