Passed
Push — master ( ff385d...f7413b )
by Robin
15:27 queued 12s
created

LazyUser::getQuota()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
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
29
class LazyUser implements IUser {
30
	private ?IUser $user = null;
31
	private DisplayNameCache $displayNameCache;
32
	private string $uid;
33
	private IUserManager $userManager;
34
35
	public function __construct(string $uid, DisplayNameCache $displayNameCache, IUserManager $userManager) {
36
		$this->displayNameCache = $displayNameCache;
37
		$this->uid = $uid;
38
		$this->userManager = $userManager;
39
	}
40
41
	private function getUser(): IUser {
42
		if ($this->user === null) {
43
			$this->user = $this->userManager->get($this->uid);
44
		}
45
		/** @var IUser */
46
		$user = $this->user;
47
		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...
48
	}
49
50
	public function getUID() {
51
		return $this->uid;
52
	}
53
54
	public function getDisplayName() {
55
		return $this->displayNameCache->getDisplayName($this->uid);
56
	}
57
58
	public function setDisplayName($displayName) {
59
		return $this->getUser()->setDisplayName($displayName);
60
	}
61
62
	public function getLastLogin() {
63
		return $this->getUser()->getLastLogin();
64
	}
65
66
	public function updateLastLoginTimestamp() {
67
		return $this->getUser()->updateLastLoginTimestamp();
68
	}
69
70
	public function delete() {
71
		return $this->getUser()->delete();
72
	}
73
74
	public function setPassword($password, $recoveryPassword = null) {
75
		return $this->getUser()->setPassword($password, $recoveryPassword);
76
	}
77
78
	public function getHome() {
79
		return $this->getUser()->getHome();
80
	}
81
82
	public function getBackendClassName() {
83
		return $this->getUser()->getBackendClassName();
84
	}
85
86
	public function getBackend() {
87
		return $this->getUser()->getBackend();
88
	}
89
90
	public function canChangeAvatar() {
91
		return $this->getUser()->canChangeAvatar();
92
	}
93
94
	public function canChangePassword() {
95
		return $this->getUser()->canChangePassword();
96
	}
97
98
	public function canChangeDisplayName() {
99
		return $this->getUser()->canChangeDisplayName();
100
	}
101
102
	public function isEnabled() {
103
		return $this->getUser()->isEnabled();
104
	}
105
106
	public function setEnabled(bool $enabled = true) {
107
		return $this->getUser()->setEnabled($enabled);
108
	}
109
110
	public function getEMailAddress() {
111
		return $this->getUser()->getEMailAddress();
112
	}
113
114
	public function getSystemEMailAddress(): ?string {
115
		return $this->getUser()->getSystemEMailAddress();
116
	}
117
118
	public function getPrimaryEMailAddress(): ?string {
119
		return $this->getUser()->getPrimaryEMailAddress();
120
	}
121
122
	public function getAvatarImage($size) {
123
		return $this->getUser()->getAvatarImage($size);
124
	}
125
126
	public function getCloudId() {
127
		return $this->getUser()->getCloudId();
128
	}
129
130
	public function setEMailAddress($mailAddress) {
131
		$this->getUser()->setEMailAddress($mailAddress);
132
	}
133
134
	public function setSystemEMailAddress(string $mailAddress): void {
135
		$this->getUser()->setSystemEMailAddress($mailAddress);
136
	}
137
138
	public function setPrimaryEMailAddress(string $mailAddress): void {
139
		$this->getUser()->setPrimaryEMailAddress($mailAddress);
140
	}
141
142
	public function getQuota() {
143
		return $this->getUser()->getQuota();
144
	}
145
146
	public function setQuota($quota) {
147
		$this->getUser()->setQuota($quota);
148
	}
149
}
150