Completed
Push — master ( 97a159...fc6227 )
by Maxence
29s
created

SearchResult::getType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
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
27
namespace OCA\Circles\Model;
28
29
30
use OCA\Circles\Exceptions\CircleTypeNotValidException;
31
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
32
use OCA\Circles\Exceptions\MemberCantJoinCircleException;
33
use OCA\Circles\Exceptions\MemberDoesNotExistException;
34
use OCA\Circles\Exceptions\MemberIsBlockedException;
35
use OCA\Circles\Exceptions\MemberIsNotAdminException;
36
use OCA\Circles\Exceptions\MemberIsNotModeratorException;
37
use OCA\Circles\Exceptions\MemberIsNotOwnerException;
38
use OCA\Circles\Exceptions\MemberIsOwnerException;
39
use OCA\Circles\Exceptions\MemberTypeCantEditLevelException;
40
use OCA\Circles\Exceptions\ModeratorIsNotHighEnoughException;
41
42
class SearchResult implements \JsonSerializable {
43
44
	/** @var string */
45
	private $ident;
46
47
	/** @var int */
48
	private $type;
49
50
	/** @var array */
51
	private $data = [];
52
53
54
	/**
55
	 * SearchResult constructor.
56
	 *
57
	 * @param string $ident
58
	 * @param int $type
59
	 * @param array $data
60
	 */
61
	function __construct($ident = '', $type = 0, $data = []) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
62
		$this->setIdent($ident);
63
		$this->setType($type);
64
		$this->setData($data);
65
	}
66
67
68
	/**
69
	 * @param string $ident
70
	 */
71
	public function setIdent($ident) {
72
		$this->ident = $ident;
73
	}
74
75
	/**
76
	 * @return string
77
	 */
78
	public function getIdent() {
79
		return $this->ident;
80
	}
81
82
83
	/**
84
	 * @param int $type
85
	 */
86
	public function setType($type) {
87
		$this->type = $type;
88
	}
89
90
	/**
91
	 * @return int
92
	 */
93
	public function getType() {
94
		return $this->type;
95
	}
96
97
98
	/**
99
	 * @param array $data
100
	 */
101
	public function setData($data) {
102
		$this->data = $data;
103
	}
104
105
	/**
106
	 * @return array
107
	 */
108
	public function getData() {
109
		if (!key_exists('display', $this->data)) {
110
			return ['display' => $this->getIdent()];
111
		}
112
113
		return $this->data;
114
	}
115
116
117
	/**
118
	 * Specify data which should be serialized to JSON
119
	 *
120
	 * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
121
	 * @return mixed data which can be serialized by <b>json_encode</b>,
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string|integer|array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
122
	 * which is a value of any type other than a resource.
123
	 * @since 5.4.0
124
	 */
125
	function jsonSerialize() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
126
127
		return [
128
			'ident' => $this->getIdent(),
129
			'type'  => $this->getType(),
130
			'data'  => $this->getData()
131
		];
132
133
	}
134
}