Completed
Push — master ( 09f896...7f4a3b )
by Maxence
03:30 queued 10s
created

TestProvider   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 185
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 18
lcom 2
cbo 2
dl 0
loc 185
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A fillIndexDocument() 0 2 1
A isDocumentUpToDate() 0 3 1
A updateDocument() 0 3 1
A onInitializingIndex() 0 2 1
A onResettingIndex() 0 2 1
A unloadProvider() 0 2 1
A improveSearchRequest() 0 2 1
A improveSearchResult() 0 2 1
A __construct() 0 7 1
A getId() 0 3 1
A getName() 0 3 1
A getConfiguration() 0 3 1
A setRunner() 0 3 1
A setIndexOptions() 0 3 1
A getSearchTemplate() 0 3 1
A loadProvider() 0 2 1
A generateChunks() 0 3 1
A generateIndexableDocuments() 0 8 1
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\Provider;
32
33
34
use OCA\FullTextSearch\Model\IndexOptions;
35
use OCA\FullTextSearch\Model\Runner;
36
use OCA\FullTextSearch\Service\ConfigService;
37
use OCA\FullTextSearch\Service\MiscService;
38
use OCA\FullTextSearch\Service\TestService;
39
use OCP\FullTextSearch\IFullTextSearchPlatform;
40
use OCP\FullTextSearch\IFullTextSearchProvider;
41
use OCP\FullTextSearch\Model\IIndex;
42
use OCP\FullTextSearch\Model\IIndexOptions;
43
use OCP\FullTextSearch\Model\IndexDocument;
44
use OCP\FullTextSearch\Model\IRunner;
45
use OCP\FullTextSearch\Model\ISearchRequest;
46
use OCP\FullTextSearch\Model\ISearchResult;
47
use OCP\FullTextSearch\Model\SearchTemplate;
48
49
50
/**
51
 * Class TestProvider
52
 *
53
 * @package OCA\FullTextSearch\Provider
54
 */
55
class TestProvider implements IFullTextSearchProvider {
56
57
58
	const TEST_PROVIDER_ID = 'test_provider';
59
60
	/** @var ConfigService */
61
	private $configService;
62
63
	/** @var TestService */
64
	private $testService;
65
66
	/** @var MiscService */
67
	private $miscService;
68
69
	/** @var Runner */
70
	private $runner;
71
72
	/** @var IndexOptions */
73
	private $indexOptions;
74
75
76
	/**
77
	 * TestProvider constructor.
78
	 *
79
	 * @param ConfigService $configService
80
	 * @param TestService $testService
81
	 * @param MiscService $miscService
82
	 */
83
	public function __construct(
84
		ConfigService $configService, TestService $testService, MiscService $miscService
85
	) {
86
		$this->configService = $configService;
87
		$this->testService = $testService;
88
		$this->miscService = $miscService;
89
	}
90
91
92
	/**
93
	 * return unique id of the provider
94
	 */
95
	public function getId(): string {
96
		return self::TEST_PROVIDER_ID;
97
	}
98
99
100
	/**
101
	 * return name of the provider
102
	 */
103
	public function getName(): string {
104
		return 'Test Provider';
105
	}
106
107
108
	/**
109
	 * @return array
110
	 */
111
	public function getConfiguration(): array {
112
		return $this->configService->getConfig();
113
	}
114
115
116
	public function setRunner(IRunner $runner) {
117
		$this->runner = $runner;
0 ignored issues
show
Documentation Bug introduced by
$runner is of type object<OCP\FullTextSearch\Model\IRunner>, but the property $runner was declared to be of type object<OCA\FullTextSearch\Model\Runner>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
118
	}
119
120
121
	/**
122
	 * @param IIndexOptions $options
123
	 */
124
	public function setIndexOptions(IIndexOptions $options) {
125
		$this->indexOptions = $options;
0 ignored issues
show
Documentation Bug introduced by
$options is of type object<OCP\FullTextSearch\Model\IIndexOptions>, but the property $indexOptions was declared to be of type object<OCA\FullTextSearch\Model\IndexOptions>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
126
	}
127
128
129
	/**
130
	 * @return SearchTemplate
131
	 */
132
	public function getSearchTemplate(): SearchTemplate {
133
		return new SearchTemplate();
134
	}
135
136
137
	/**
138
	 * called when loading all providers.
139
	 *
140
	 * Loading some containers.
141
	 */
142
	public function loadProvider() {
143
	}
144
145
146
	public function generateChunks(string $userId): array {
147
		return [];
148
	}
149
150
151
	/**
152
	 * returns all indexable document for a user.
153
	 * There is no need to fill the document with content at this point.
154
	 *
155
	 * $platform is provided if the mapping needs to be changed.
156
	 *
157
	 * @param string $userId
158
	 * @param string $chunk
159
	 *
160
	 * @return IndexDocument[]
161
	 */
162
	public function generateIndexableDocuments(string $userId, string $chunk): array {
163
		$result = [];
164
165
		$result[] = $this->testService->generateIndexDocumentContentLicense($this->indexOptions);
166
		$result[] = $this->testService->generateIndexDocumentSimple($this->indexOptions);
167
168
		return $result;
169
	}
170
171
172
	/**
173
	 * generate documents prior to the indexing.
174
	 *
175
	 * @param IndexDocument $document
176
	 */
177
	public function fillIndexDocument(IndexDocument $document) {
178
	}
179
180
181
	/**
182
	 * @param IndexDocument $document
183
	 *
184
	 * @return bool
185
	 */
186
	public function isDocumentUpToDate(IndexDocument $document): bool {
187
		return false;
188
	}
189
190
191
	/**
192
	 * @param IIndex $index
193
	 *
194
	 * @return IndexDocument
195
	 */
196
	public function updateDocument(IIndex $index): IndexDocument {
197
		return null;
198
	}
199
200
201
	/**
202
	 * @param IFullTextSearchPlatform $platform
203
	 */
204
	public function onInitializingIndex(IFullTextSearchPlatform $platform) {
205
	}
206
207
208
	/**
209
	 * @param IFullTextSearchPlatform $platform
210
	 */
211
	public function onResettingIndex(IFullTextSearchPlatform $platform) {
212
	}
213
214
215
	/**
216
	 * not used yet
217
	 */
218
	public function unloadProvider() {
219
	}
220
221
222
	/**
223
	 * before a search, improve the request
224
	 *
225
	 * @param ISearchRequest $request
226
	 */
227
	public function improveSearchRequest(ISearchRequest $request) {
228
	}
229
230
231
	/**
232
	 * after a search, improve results
233
	 *
234
	 * @param ISearchResult $searchResult
235
	 */
236
	public function improveSearchResult(ISearchResult $searchResult) {
237
	}
238
239
}
240
241