Completed
Pull Request — master (#1128)
by René
05:00
created

UserGroupClass::getLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 1
c 3
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Model;
25
26
class UserGroupClass implements \JsonSerializable {
27
	public const TYPE = 'generic';
28
	public const TYPE_PUBLIC = 'public';
29
	public const TYPE_EXTERNAL = 'external';
30
31
	private $l10n;
32
33
	/** @var string */
34
	protected $id;
35
36
	/** @var string */
37
	protected $type;
38
39
	/** @var string */
40
	protected $displayName = '';
41
42
	/** @var string */
43
	protected $description = '';
44
45
	/** @var string */
46
	protected $emailAddress = '';
47
48
	/** @var string */
49
	protected $language = '';
50
51
	/** @var string */
52
	protected $organisation = '';
53
54
	/** @var string */
55
	protected $icon = '';
56
57
	/** @var boolean */
58
	protected $isNoUser = true;
59
60
	/** @var string[] */
61
	protected $categories = [];
62
63
	/**
64
	 * User constructor.
65
	 * @param $id
66
	 * @param $displayName
67
	 */
68
	public function __construct(
69
		$id,
70
		$type,
71
		$displayName = '',
72
		$emailAddress = '',
73
		$language = ''
74
	) {
75
		$this->id = $id;
76
		$this->type = $type;
77
		$this->displayName = $displayName;
78
		$this->emailAddress = $emailAddress;
79
		$this->language = $language;
80
		$this->icon = 'icon-share';
81
		$this->l10n = \OC::$server->getL10N('polls');
82
	}
83
84
	/**
85
	 * getId
86
	 * @NoAdminRequired
87
	 * @return String
88
	 */
89
	public function getId() {
90
		return $this->id;
91
	}
92
93
	/**
94
	 * getUser
95
	 * @NoAdminRequired
96
	 * @return String
97
	 */
98
	public function getUser() {
99
		return $this->id;
100
	}
101
102
	/**
103
	 * getType
104
	 * @NoAdminRequired
105
	 * @return String
106
	 */
107
	public function getType() {
108
		return $this->type;
109
	}
110
111
	/**
112
	 * getLanguage
113
	 * @NoAdminRequired
114
	 * @return String
115
	 */
116
	public function getLanguage() {
117
		return $this->language;
118
	}
119
120
	/**
121
	 * getDisplayName
122
	 * @NoAdminRequired
123
	 * @return String
124
	 */
125
	public function getDisplayName() {
126
		return $this->displayName;
127
	}
128
129
	/**
130
	 * getDescription
131
	 * @NoAdminRequired
132
	 * @return String
133
	 */
134
	public function getDescription() {
135
		return $this->description;
136
	}
137
138
	/**
139
	 * getIcon
140
	 * @NoAdminRequired
141
	 * @return String
142
	 */
143
	public function getIcon() {
144
		return $this->icon;
145
	}
146
147
	/**
148
	 * getEmailAddress
149
	 * @NoAdminRequired
150
	 * @return String
151
	 */
152
	public function getEmailAddress() {
153
		return $this->emailAddress;
154
	}
155
156
	/**
157
	 * getOrganisation
158
	 * @NoAdminRequired
159
	 * @return String
160
	 */
161
	public function getOrganisation() {
162
		return $this->organisation;
163
	}
164
165
	/**
166
	 * getCategories
167
	 * @NoAdminRequired
168
	 * @return Array
169
	 */
170
	public function getCategories() {
171
		return $this->categories;
172
	}
173
174
	/**
175
	 * getOrganisation
176
	 * @NoAdminRequired
177
	 * @return String
178
	 */
179
	public function getIsNoUser() {
180
		return $this->isNoUser;
181
	}
182
183
	/**
184
	 * setType
185
	 * @NoAdminRequired
186
	 * @param string $type
187
	 * @return String
188
	 */
189
	public function setType($type) {
190
		$this->type = $type;
191
		return $this->type;
192
	}
193
194
	/**
195
	 * setDisplayName
196
	 * @NoAdminRequired
197
	 * @param string $displayName
198
	 * @return String
199
	 */
200
	public function setDisplayName($displayName) {
201
		$this->displayName = $displayName;
202
		return $this->displayName;
203
	}
204
205
	/**
206
	 * setDescription
207
	 * @NoAdminRequired
208
	 * @param string $description
209
	 * @return String
210
	 */
211
	public function setDescription($description) {
212
		$this->description = $description;
213
		return $this->description;
214
	}
215
216
	/**
217
	 * setEmailAddress
218
	 * @NoAdminRequired
219
	 * @param string $emailAddress
220
	 * @return String
221
	 */
222
	public function setEmailAddress($emailAddress) {
223
		$this->emailAddress = $emailAddress;
224
		return $this->emailAddress;
225
	}
226
227
	/**
228
	 * setLanguage
229
	 * @NoAdminRequired
230
	 * @param string $language
231
	 * @return String
232
	 */
233
	public function setLanguage($language) {
234
		$this->language = $language;
235
		return $this->language;
236
	}
237
238
	/**
239
	 * setOrganisation
240
	 * @NoAdminRequired
241
	 * @param string $organisation
242
	 * @return String
243
	 */
244
	public function setOrganisation($organisation) {
245
		$this->organisation = $organisation;
246
		return $this->organisation;
247
	}
248
249
	/**
250
	 * search
251
	 * @NoAdminRequired
252
	 * @return Array
253
	 */
254
	public static function search() {
255
		return [];
256
	}
257
258
	public static function getUserGroupChild($type, $id, $displayName = '', $emailAddress = '') {
259
		switch ($type) {
260
			case Group::TYPE:
261
				return new Group($id);
262
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
263
			case Circle::TYPE:
264
				return new Circle($id);
265
				break;
266
			case Contact::TYPE:
267
				return new Contact($id);
268
				break;
269
			case ContactGroup::TYPE:
270
				return new ContactGroup($id);
271
				break;
272
			case User::TYPE:
273
				return new User($id);
274
				break;
275
			case Email::TYPE:
276
				return new Email($id);
277
				break;
278
			case self::TYPE_PUBLIC:
279
				return new GenericUser($id,self::TYPE_PUBLIC);
280
				break;
281
			case self::TYPE_EXTERNAL:
282
				return new GenericUser($id, self::TYPE_EXTERNAL, $displayName, $emailAddress);
283
				break;
284
			default:
285
				throw new InvalidShareType('Invalid share type (' . $type . ')');
0 ignored issues
show
Bug introduced by
The type OCA\Polls\Model\InvalidShareType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
286
			}
287
	}
288
289
	/**
290
	 * @return array
291
	 */
292
	public function jsonSerialize(): array {
293
		return	[
294
			'id'        	=> $this->getId(),
295
			'user'          => $this->getId(),
296
			'userId'        => $this->getId(),
297
			'type'       	=> $this->getType(),
298
			'displayName'	=> $this->getDisplayName(),
299
			'organisation'	=> $this->getOrganisation(),
300
			'emailAddress'	=> $this->getEmailAddress(),
301
			'language'		=> $this->getLanguage(),
302
			'desc' 			=> $this->getDescription(),
303
			'icon'			=> $this->getIcon(),
304
			'categories'	=> $this->getCategories(),
305
			'isNoUser'		=> $this->getIsNoUser(),
306
		];
307
	}
308
}
309