Passed
Push — master ( 7972a5...654cd1 )
by Christoph
11:53 queued 12s
created

FilesSearchProvider::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright 2020 Christoph Wurst <[email protected]>
7
 *
8
 * @author 2020 Christoph Wurst <[email protected]>
9
 *
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
namespace OCA\Files\Search;
27
28
use OC\Search\Provider\File;
29
use OC\Search\Result\File as FileResult;
30
use OCP\IL10N;
31
use OCP\IURLGenerator;
32
use OCP\IUser;
33
use OCP\Search\IProvider;
34
use OCP\Search\ISearchQuery;
35
use OCP\Search\SearchResult;
36
37
class FilesSearchProvider implements IProvider {
38
39
	/** @var File */
40
	private $fileSearch;
41
42
	/** @var IL10N */
43
	private $l10n;
44
45
	/** @var IURLGenerator */
46
	private $urlGenerator;
47
48
	public function __construct(File $fileSearch,
49
								IL10N $l10n,
50
								IURLGenerator $urlGenerator) {
51
		$this->l10n = $l10n;
52
		$this->fileSearch = $fileSearch;
53
		$this->urlGenerator = $urlGenerator;
54
	}
55
56
	public function getId(): string {
57
		return 'files';
58
	}
59
60
	public function search(IUser $user, ISearchQuery $query): SearchResult {
61
		return SearchResult::complete(
62
			$this->l10n->t('Files'),
63
			array_map(function (FileResult $result) {
64
				return new FilesSearchResultEntry(
65
					$this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id]),
0 ignored issues
show
Deprecated Code introduced by
The property OCP\Search\Result::$id has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

65
					$this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => /** @scrutinizer ignore-deprecated */ $result->id]),

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
66
					$result->name,
0 ignored issues
show
Deprecated Code introduced by
The property OCP\Search\Result::$name has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

66
					/** @scrutinizer ignore-deprecated */ $result->name,

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
67
					$result->path,
0 ignored issues
show
Deprecated Code introduced by
The property OC\Search\Result\File::$path has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

67
					/** @scrutinizer ignore-deprecated */ $result->path,

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
68
					$result->link
0 ignored issues
show
Deprecated Code introduced by
The property OCP\Search\Result::$link has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

68
					/** @scrutinizer ignore-deprecated */ $result->link

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
69
				);
70
			}, $this->fileSearch->search($query->getTerm()))
0 ignored issues
show
Bug introduced by
$this->fileSearch->search($query->getTerm()) of type OCP\Search\Result is incompatible with the type array expected by parameter $arr1 of array_map(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
			}, /** @scrutinizer ignore-type */ $this->fileSearch->search($query->getTerm()))
Loading history...
Deprecated Code introduced by
The function OC\Search\Provider\File::search() has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

70
			}, /** @scrutinizer ignore-deprecated */ $this->fileSearch->search($query->getTerm()))

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
71
		);
72
	}
73
}
74