Passed
Push — master ( 058135...a4d511 )
by John
13:28 queued 12s
created

CommentsSearchProvider::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
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\IUserManager;
32
use OCP\Search\IProvider;
33
use OCP\Search\ISearchQuery;
34
use OCP\Search\SearchResult;
35
use OCP\Search\SearchResultEntry;
36
use function array_map;
37
use function pathinfo;
38
39
class CommentsSearchProvider implements IProvider {
40
41
	/** @var IUserManager */
42
	private $userManager;
43
44
	/** @var IL10N */
45
	private $l10n;
46
47
	/** @var IURLGenerator */
48
	private $urlGenerator;
49
50
	/** @var LegacyProvider */
51
	private $legacyProvider;
52
53
	public function __construct(IUserManager $userManager,
54
								IL10N $l10n,
55
								IURLGenerator $urlGenerator,
56
								LegacyProvider $legacyProvider) {
57
		$this->userManager = $userManager;
58
		$this->l10n = $l10n;
59
		$this->urlGenerator = $urlGenerator;
60
		$this->legacyProvider = $legacyProvider;
61
	}
62
63
	/**
64
	 * @inheritDoc
65
	 */
66
	public function getId(): string {
67
		return 'comments';
68
	}
69
70
	/**
71
	 * @inheritDoc
72
	 */
73
	public function getName(): string {
74
		return $this->l10n->t('Comments');
75
	}
76
77
	/**
78
	 * @inheritDoc
79
	 */
80
	public function getOrder(): int {
81
		return 10;
82
	}
83
84
	/**
85
	 * @inheritDoc
86
	 */
87
	public function search(IUser $user, ISearchQuery $query): SearchResult {
88
		return SearchResult::complete(
89
			$this->l10n->t('Comments'),
90
			array_map(function (Result $result) {
91
				$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

91
				$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...
92
				$pathInfo = pathinfo($path);
93
				$isUser = $this->userManager->userExists($result->authorId);
0 ignored issues
show
Deprecated Code introduced by
The property OCA\Comments\Search\Result::$authorId 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

93
				$isUser = $this->userManager->userExists(/** @scrutinizer ignore-deprecated */ $result->authorId);

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...
94
				$avatarUrl = $isUser
95
					? $this->urlGenerator->linkToRoute('core.avatar.getAvatar', ['userId' => $result->authorId, 'size' => 42])
0 ignored issues
show
Deprecated Code introduced by
The property OCA\Comments\Search\Result::$authorId 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

95
					? $this->urlGenerator->linkToRoute('core.avatar.getAvatar', ['userId' => /** @scrutinizer ignore-deprecated */ $result->authorId, 'size' => 42])

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...
96
					: $this->urlGenerator->linkToRoute('core.GuestAvatar.getAvatar', ['guestName' => $result->authorId, 'size' => 42]);
0 ignored issues
show
Deprecated Code introduced by
The property OCA\Comments\Search\Result::$authorId 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

96
					: $this->urlGenerator->linkToRoute('core.GuestAvatar.getAvatar', ['guestName' => /** @scrutinizer ignore-deprecated */ $result->authorId, 'size' => 42]);

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...
97
				return new SearchResultEntry(
98
					$avatarUrl,
99
					$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

99
					/** @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...
100
					$path,
101
					$this->urlGenerator->linkToRoute('files.view.index',[
102
						'dir' => $pathInfo['dirname'],
103
						'scrollto' => $pathInfo['basename'],
104
					]),
105
					'',
106
					true
107
				);
108
			}, $this->legacyProvider->search($query->getTerm()))
109
		);
110
	}
111
}
112