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
|
|
|
|
30
|
|
|
class IndexOptions implements \JsonSerializable { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private $options = []; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public function __construct($options = []) { |
39
|
|
|
$this->options = $options; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function getOptions() { |
46
|
|
|
return $this->options; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param array $options |
51
|
|
|
*/ |
52
|
|
|
public function setOptions($options) { |
53
|
|
|
$this->options = $options; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $k |
58
|
|
|
* @param string $v |
59
|
|
|
*/ |
60
|
|
|
public function addOption($k, $v) { |
61
|
|
|
$this->options[$k] = $v; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $k |
66
|
|
|
* @param array $array |
67
|
|
|
*/ |
68
|
|
|
public function addOptionArray($k, $array) { |
69
|
|
|
$this->options[$k] = $array; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string $k |
74
|
|
|
* @param bool $bool |
75
|
|
|
*/ |
76
|
|
|
public function addOptionBool($k, $bool) { |
77
|
|
|
$this->options[$k] = $bool; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $k |
83
|
|
|
* @param string $default |
84
|
|
|
* |
85
|
|
|
* @return string |
86
|
|
|
*/ |
87
|
|
|
public function getOption($k, $default = '') { |
88
|
|
|
if (array_key_exists($k, $this->options)) { |
89
|
|
|
return $this->options[$k]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $default; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $option |
98
|
|
|
* @param array $default |
99
|
|
|
* |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
View Code Duplication |
public function getOptionArray($option, $default = []) { |
|
|
|
|
103
|
|
|
if (array_key_exists($option, $this->options)) { |
104
|
|
|
$options = $this->options[$option]; |
105
|
|
|
if (is_array($options)) { |
106
|
|
|
return $this->options[$option]; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $default; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $option |
116
|
|
|
* @param bool $default |
117
|
|
|
* |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
View Code Duplication |
public function getOptionBool($option, $default) { |
|
|
|
|
121
|
|
|
if (array_key_exists($option, $this->options)) { |
122
|
|
|
$options = $this->options[$option]; |
123
|
|
|
if (is_bool($options)) { |
124
|
|
|
return $this->options[$option]; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $default; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Specify data which should be serialized to JSON |
134
|
|
|
* |
135
|
|
|
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php |
136
|
|
|
* @return mixed data which can be serialized by <b>json_encode</b>, |
137
|
|
|
* which is a value of any type other than a resource. |
138
|
|
|
* @since 5.4.0 |
139
|
|
|
*/ |
140
|
|
|
public function jsonSerialize() { |
141
|
|
|
return $this->options; |
142
|
|
|
} |
143
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.