Passed
Push — master ( 7e3d5d...244031 )
by Christoph
17:27 queued 12s
created

LazyUser::setEMailAddress()   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 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * @copyright Copyright (c) 2022 Robin Appelman <[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 OC\User;
25
26
use OCP\IUser;
27
use OCP\IUserManager;
28
use OCP\UserInterface;
29
30
class LazyUser implements IUser {
31
	private ?IUser $user = null;
32
	private string $uid;
33
	private ?string $displayName;
34
	private IUserManager $userManager;
35
	private ?UserInterface $backend;
36
37
	public function __construct(string $uid, IUserManager $userManager, ?string $displayName = null, ?UserInterface $backend = null) {
38
		$this->uid = $uid;
39
		$this->userManager = $userManager;
40
		$this->displayName = $displayName;
41
		$this->backend = $backend;
42
	}
43
44
	private function getUser(): IUser {
45
		if ($this->user === null) {
46
			if ($this->backend) {
47
				/** @var \OC\User\Manager $manager */
48
				$manager = $this->userManager;
49
				$this->user = $manager->getUserObject($this->uid, $this->backend);
50
			} else {
51
				$this->user = $this->userManager->get($this->uid);
52
			}
53
		}
54
		/** @var IUser */
55
		$user = $this->user;
56
		return $user;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $user could return the type null which is incompatible with the type-hinted return OCP\IUser. Consider adding an additional type-check to rule them out.
Loading history...
57
	}
58
59
	public function getUID() {
60
		return $this->uid;
61
	}
62
63
	public function getDisplayName() {
64
		if ($this->displayName) {
65
			return $this->displayName;
66
		}
67
68
		return $this->userManager->getDisplayName($this->uid) ?? $this->uid;
69
	}
70
71
	public function setDisplayName($displayName) {
72
		return $this->getUser()->setDisplayName($displayName);
73
	}
74
75
	public function getLastLogin() {
76
		return $this->getUser()->getLastLogin();
77
	}
78
79
	public function updateLastLoginTimestamp() {
80
		return $this->getUser()->updateLastLoginTimestamp();
81
	}
82
83
	public function delete() {
84
		return $this->getUser()->delete();
85
	}
86
87
	public function setPassword($password, $recoveryPassword = null) {
88
		return $this->getUser()->setPassword($password, $recoveryPassword);
89
	}
90
91
	public function getHome() {
92
		return $this->getUser()->getHome();
93
	}
94
95
	public function getBackendClassName() {
96
		return $this->getUser()->getBackendClassName();
97
	}
98
99
	public function getBackend(): ?UserInterface {
100
		return $this->getUser()->getBackend();
101
	}
102
103
	public function canChangeAvatar() {
104
		return $this->getUser()->canChangeAvatar();
105
	}
106
107
	public function canChangePassword() {
108
		return $this->getUser()->canChangePassword();
109
	}
110
111
	public function canChangeDisplayName() {
112
		return $this->getUser()->canChangeDisplayName();
113
	}
114
115
	public function isEnabled() {
116
		return $this->getUser()->isEnabled();
117
	}
118
119
	public function setEnabled(bool $enabled = true) {
120
		return $this->getUser()->setEnabled($enabled);
121
	}
122
123
	public function getEMailAddress() {
124
		return $this->getUser()->getEMailAddress();
125
	}
126
127
	public function getSystemEMailAddress(): ?string {
128
		return $this->getUser()->getSystemEMailAddress();
129
	}
130
131
	public function getPrimaryEMailAddress(): ?string {
132
		return $this->getUser()->getPrimaryEMailAddress();
133
	}
134
135
	public function getAvatarImage($size) {
136
		return $this->getUser()->getAvatarImage($size);
137
	}
138
139
	public function getCloudId() {
140
		return $this->getUser()->getCloudId();
141
	}
142
143
	public function setEMailAddress($mailAddress) {
144
		$this->getUser()->setEMailAddress($mailAddress);
145
	}
146
147
	public function setSystemEMailAddress(string $mailAddress): void {
148
		$this->getUser()->setSystemEMailAddress($mailAddress);
149
	}
150
151
	public function setPrimaryEMailAddress(string $mailAddress): void {
152
		$this->getUser()->setPrimaryEMailAddress($mailAddress);
153
	}
154
155
	public function getQuota() {
156
		return $this->getUser()->getQuota();
157
	}
158
159
	public function setQuota($quota) {
160
		$this->getUser()->setQuota($quota);
161
	}
162
163
	public function getManagerUids(): array {
164
		return $this->getUser()->getManagerUids();
165
	}
166
167
	public function setManagerUids(array $uids): void {
168
		$this->getUser()->setManagerUids($uids);
169
	}
170
}
171