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

Provider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 6
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\Comments\Search;
27
28
use OCP\IL10N;
29
use OCP\IURLGenerator;
30
use OCP\IUser;
31
use OCP\Search\IProvider;
32
use OCP\Search\ISearchQuery;
33
use OCP\Search\SearchResult;
34
use function array_map;
35
use function pathinfo;
36
37
class Provider implements IProvider {
38
39
	/** @var IL10N */
40
	private $l10n;
41
42
	/** @var IURLGenerator */
43
	private $urlGenerator;
44
45
	/** @var LegacyProvider */
46
	private $legacyProvider;
47
48
	public function __construct(IL10N $l10n,
49
								IURLGenerator $urlGenerator,
50
								LegacyProvider $legacyProvider) {
51
		$this->l10n = $l10n;
52
		$this->urlGenerator = $urlGenerator;
53
		$this->legacyProvider = $legacyProvider;
54
	}
55
56
	public function getId(): string {
57
		return 'comments';
58
	}
59
60
	public function search(IUser $user, ISearchQuery $query): SearchResult {
61
		return SearchResult::complete(
62
			$this->l10n->t('Comments'),
63
			array_map(function (Result $result) {
64
				$path = $result->path;
0 ignored issues
show
Deprecated Code introduced by
The property OCA\Comments\Search\Result::$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

64
				$path = /** @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...
65
				$pathInfo = pathinfo($path);
66
				return new CommentsSearchResultEntry(
67
					$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

67
					$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...
68
					$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

68
					/** @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...
69
					$path,
70
					$this->urlGenerator->linkToRoute(
71
						'files.view.index',
72
						[
73
							'dir' => $pathInfo['dirname'],
74
							'scrollto' => $pathInfo['basename'],
75
						]
76
					)
77
				);
78
			}, $this->legacyProvider->search($query->getTerm()))
79
		);
80
	}
81
}
82