Completed
Pull Request — master (#1128)
by René
04:35
created

User   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 6
eloc 18
c 2
b 0
f 2
dl 0
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserIsDisabled() 0 2 1
A listRaw() 0 2 1
A __construct() 0 13 1
A search() 0 8 3
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
25
namespace OCA\Polls\Model;
26
27
28
class User extends UserGroupClass  {
29
	public const TYPE = 'user';
30
	public const ICON = 'icon-user';
31
32
	/**
33
	 * User constructor.
34
	 * @param $id
35
	 */
36
	public function __construct(
37
		$id
38
	) {
39
		parent::__construct($id, self::TYPE);
40
		$this->icon = self::ICON;
41
		$this->isNoUser = false;
0 ignored issues
show
Documentation Bug introduced by
The property $isNoUser was declared of type string, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
42
43
		$this->user = \OC::$server->getUserManager()->get($this->id);
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
44
		$this->language = \OC::$server->getConfig()->getUserValue($this->id, 'core', 'lang');
45
46
		$this->displayName = \OC::$server->getUserManager()->get($this->id)->getDisplayName();
47
		$this->description = \OC::$server->getL10N('polls')->t('User');
48
		$this->emailAddress = $this->user->getEMailAddress();
49
	}
50
51
	/**
52
	 * getUserIsDisabled
53
	 * @NoAdminRequired
54
	 * @return Boolean
55
	 */
56
	public function getUserIsDisabled() {
57
		return !\OC::$server->getUserManager()->get($this->id)->isEnabled();
58
	}
59
60
	/**
61
	 * listRaw
62
	 * @NoAdminRequired
63
	 * @param string $query
64
	 * @return Array
65
	 */
66
	public static function listRaw($query = '') {
67
		return \OC::$server->getUserManager()->search($query);
68
	}
69
70
	/**
71
	 * search
72
	 * @NoAdminRequired
73
	 * @param string $query
74
	 * @param array $skip - group names to skip in return array
75
	 * @return User[]
76
	 */
77
	public static function search($query = '', $skip = []) {
78
		$users = [];
79
		foreach (self::listRaw($query) as $user) {
80
			if (!in_array($user->getUID(), $skip)) {
81
				$users[] = new Self($user->getUID());
82
			}
83
		}
84
		return $users;
85
	}
86
}
87