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

ASearchResultEntry::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
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 OCP\Search;
27
28
use JsonSerializable;
29
30
/**
31
 * Represents an entry in a list of results an app returns for a unified search
32
 * query.
33
 *
34
 * The app providing the results has to extend this class for customization. In
35
 * most cases apps do not have to add any additional code.
36
 *
37
 * @example ``class MailResultEntry extends ASearchResultEntry {}`
38
 *
39
 * This approach was chosen over a final class as it allows Nextcloud to later
40
 * add new optional properties of an entry without having to break the usage of
41
 * this class in apps.
42
 *
43
 * @since 20.0.0
44
 */
45
abstract class ASearchResultEntry implements JsonSerializable {
46
47
	/**
48
	 * @var string
49
	 * @since 20.0.0
50
	 */
51
	protected $thumbnailUrl;
52
53
	/**
54
	 * @var string
55
	 * @since 20.0.0
56
	 */
57
	protected $title;
58
59
	/**
60
	 * @var string
61
	 * @since 20.0.0
62
	 */
63
	protected $subline;
64
65
	/**
66
	 * @var string
67
	 * @since 20.0.0
68
	 */
69
	protected $resourceUrl;
70
71
	/**
72
	 * @param string $thumbnailUrl a relative or absolute URL to the thumbnail or icon of the entry
73
	 * @param string $title a main title of the entry
74
	 * @param string $subline the secondary line of the entry
75
	 * @param string $resourceUrl the URL where the user can find the detail, like a deep link inside the app
76
	 *
77
	 * @since 20.0.0
78
	 */
79
	public function __construct(string $thumbnailUrl,
80
								string $title,
81
								string $subline,
82
								string $resourceUrl) {
83
		$this->thumbnailUrl = $thumbnailUrl;
84
		$this->title = $title;
85
		$this->subline = $subline;
86
		$this->resourceUrl = $resourceUrl;
87
	}
88
89
	/**
90
	 * @return array
91
	 *
92
	 * @since 20.0.0
93
	 */
94
	public function jsonSerialize(): array {
95
		return [
96
			'thumbnailUrl' => $this->thumbnailUrl,
97
			'title' => $this->title,
98
			'subline' => $this->subline,
99
			'resourceUrl' => $this->resourceUrl,
100
		];
101
	}
102
}
103