Skip to content

Commit c20fccc

Browse files
authored
Merge pull request #59379 from nextcloud/fix/clean-ldap-ocp-typing
fix: Fix typing in LDAP provider public interfaces
2 parents f34d7be + 99a8e6c commit c20fccc

5 files changed

Lines changed: 56 additions & 71 deletions

File tree

apps/user_ldap/lib/LDAPProvider.php

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\User_LDAP;
1010

11+
use LDAP\Connection;
1112
use OCA\User_LDAP\User\DeletedUsersIndex;
1213
use OCP\GroupInterface;
1314
use OCP\IGroupManager;
@@ -64,7 +65,7 @@ public function __construct(
6465
* @return string with the LDAP DN
6566
* @throws \Exception if translation was unsuccessful
6667
*/
67-
public function getUserDN($uid) {
68+
public function getUserDN(string $uid): string {
6869
if (!$this->userBackend->userExists($uid)) {
6970
throw new \Exception('User id not found in LDAP');
7071
}
@@ -77,11 +78,9 @@ public function getUserDN($uid) {
7778

7879
/**
7980
* Translate a group id to LDAP DN.
80-
* @param string $gid group id
81-
* @return string
8281
* @throws \Exception
8382
*/
84-
public function getGroupDN($gid) {
83+
public function getGroupDN(string $gid): string {
8584
if (!$this->groupBackend->groupExists($gid)) {
8685
throw new \Exception('Group id not found in LDAP');
8786
}
@@ -95,11 +94,10 @@ public function getGroupDN($gid) {
9594
/**
9695
* Translate a LDAP DN to an internal user name. If there is no mapping between
9796
* the DN and the user name, a new one will be created.
98-
* @param string $dn LDAP DN
99-
* @return string with the internal user name
97+
* @return string the internal user name
10098
* @throws \Exception if translation was unsuccessful
10199
*/
102-
public function getUserName($dn) {
100+
public function getUserName(string $dn): string {
103101
$result = $this->userBackend->dn2UserName($dn);
104102
if (!$result) {
105103
throw new \Exception('Translation to internal user name unsuccessful');
@@ -109,30 +107,24 @@ public function getUserName($dn) {
109107

110108
/**
111109
* Convert a stored DN so it can be used as base parameter for LDAP queries.
112-
* @param string $dn the DN in question
113-
* @return string
114110
*/
115-
public function DNasBaseParameter($dn) {
111+
public function DNasBaseParameter(string $dn): string {
116112
return $this->helper->DNasBaseParameter($dn);
117113
}
118114

119115
/**
120116
* Sanitize a DN received from the LDAP server.
121-
* @param array|string $dn the DN in question
122-
* @return array|string the sanitized DN
123117
*/
124-
public function sanitizeDN($dn) {
118+
public function sanitizeDN(array|string $dn): array|string {
125119
return $this->helper->sanitizeDN($dn);
126120
}
127121

128122
/**
129123
* Return a new LDAP connection resource for the specified user.
130124
* The connection must be closed manually.
131-
* @param string $uid user id
132-
* @return \LDAP\Connection The LDAP connection
133125
* @throws \Exception if user id was not found in LDAP
134126
*/
135-
public function getLDAPConnection($uid) {
127+
public function getLDAPConnection(string $uid): Connection {
136128
if (!$this->userBackend->userExists($uid)) {
137129
throw new \Exception('User id not found in LDAP');
138130
}
@@ -142,11 +134,9 @@ public function getLDAPConnection($uid) {
142134
/**
143135
* Return a new LDAP connection resource for the specified user.
144136
* The connection must be closed manually.
145-
* @param string $gid group id
146-
* @return \LDAP\Connection The LDAP connection
147137
* @throws \Exception if group id was not found in LDAP
148138
*/
149-
public function getGroupLDAPConnection($gid) {
139+
public function getGroupLDAPConnection(string $gid): Connection {
150140
if (!$this->groupBackend->groupExists($gid)) {
151141
throw new \Exception('Group id not found in LDAP');
152142
}
@@ -155,11 +145,9 @@ public function getGroupLDAPConnection($gid) {
155145

156146
/**
157147
* Get the LDAP base for users.
158-
* @param string $uid user id
159-
* @return string the base for users
160148
* @throws \Exception if user id was not found in LDAP
161149
*/
162-
public function getLDAPBaseUsers($uid) {
150+
public function getLDAPBaseUsers(string $uid): string {
163151
if (!$this->userBackend->userExists($uid)) {
164152
throw new \Exception('User id not found in LDAP');
165153
}
@@ -185,11 +173,9 @@ public function getLDAPBaseUsers($uid) {
185173

186174
/**
187175
* Get the LDAP base for groups.
188-
* @param string $uid user id
189-
* @return string the base for groups
190176
* @throws \Exception if user id was not found in LDAP
191177
*/
192-
public function getLDAPBaseGroups($uid) {
178+
public function getLDAPBaseGroups(string $uid): string {
193179
if (!$this->userBackend->userExists($uid)) {
194180
throw new \Exception('User id not found in LDAP');
195181
}
@@ -199,10 +185,9 @@ public function getLDAPBaseGroups($uid) {
199185

200186
/**
201187
* Clear the cache if a cache is used, otherwise do nothing.
202-
* @param string $uid user id
203188
* @throws \Exception if user id was not found in LDAP
204189
*/
205-
public function clearCache($uid) {
190+
public function clearCache(string $uid): void {
206191
if (!$this->userBackend->userExists($uid)) {
207192
throw new \Exception('User id not found in LDAP');
208193
}
@@ -212,10 +197,9 @@ public function clearCache($uid) {
212197
/**
213198
* Clear the cache if a cache is used, otherwise do nothing.
214199
* Acts on the LDAP connection of a group
215-
* @param string $gid group id
216200
* @throws \Exception if user id was not found in LDAP
217201
*/
218-
public function clearGroupCache($gid) {
202+
public function clearGroupCache(string $gid): void {
219203
if (!$this->groupBackend->groupExists($gid)) {
220204
throw new \Exception('Group id not found in LDAP');
221205
}
@@ -224,37 +208,31 @@ public function clearGroupCache($gid) {
224208

225209
/**
226210
* Check whether a LDAP DN exists
227-
* @param string $dn LDAP DN
228-
* @return bool whether the DN exists
229211
*/
230-
public function dnExists($dn) {
212+
public function dnExists(string $dn): bool {
231213
$result = $this->userBackend->dn2UserName($dn);
232214
return !$result ? false : true;
233215
}
234216

235217
/**
236218
* Flag record for deletion.
237-
* @param string $uid user id
238219
*/
239-
public function flagRecord($uid) {
220+
public function flagRecord(string $uid): void {
240221
$this->deletedUsersIndex->markUser($uid);
241222
}
242223

243224
/**
244225
* Unflag record for deletion.
245-
* @param string $uid user id
246226
*/
247-
public function unflagRecord($uid) {
227+
public function unflagRecord(string $uid): void {
248228
//do nothing
249229
}
250230

251231
/**
252232
* Get the LDAP attribute name for the user's display name
253-
* @param string $uid user id
254-
* @return string the display name field
255233
* @throws \Exception if user id was not found in LDAP
256234
*/
257-
public function getLDAPDisplayNameField($uid) {
235+
public function getLDAPDisplayNameField(string $uid): string {
258236
if (!$this->userBackend->userExists($uid)) {
259237
throw new \Exception('User id not found in LDAP');
260238
}
@@ -263,11 +241,9 @@ public function getLDAPDisplayNameField($uid) {
263241

264242
/**
265243
* Get the LDAP attribute name for the email
266-
* @param string $uid user id
267-
* @return string the email field
268244
* @throws \Exception if user id was not found in LDAP
269245
*/
270-
public function getLDAPEmailField($uid) {
246+
public function getLDAPEmailField(string $uid): string {
271247
if (!$this->userBackend->userExists($uid)) {
272248
throw new \Exception('User id not found in LDAP');
273249
}
@@ -276,11 +252,9 @@ public function getLDAPEmailField($uid) {
276252

277253
/**
278254
* Get the LDAP type of association between users and groups
279-
* @param string $gid group id
280-
* @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber', ''
281255
* @throws \Exception if group id was not found in LDAP
282256
*/
283-
public function getLDAPGroupMemberAssoc($gid) {
257+
public function getLDAPGroupMemberAssoc(string $gid): string {
284258
if (!$this->groupBackend->groupExists($gid)) {
285259
throw new \Exception('Group id not found in LDAP');
286260
}

lib/private/LDAP/NullLDAPProviderFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class NullLDAPProviderFactory implements ILDAPProviderFactory {
1515
public function __construct(IServerContainer $serverContainer) {
1616
}
1717

18-
public function getLDAPProvider() {
18+
public function getLDAPProvider(): never {
1919
throw new \Exception('No LDAP provider is available');
2020
}
2121

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-License-Identifier: AGPL-3.0-or-later
68
*/
9+
710
namespace OCP\LDAP;
811

12+
use OCP\AppFramework\Attribute\Consumable;
13+
914
/**
1015
* Interface IDeletionFlagSupport
1116
*
1217
* @since 11.0.0
1318
*/
19+
#[Consumable(since: '11.0.0')]
1420
interface IDeletionFlagSupport {
1521
/**
1622
* Flag record for deletion.
1723
* @param string $uid user id
1824
* @since 11.0.0
1925
*/
20-
public function flagRecord($uid);
26+
public function flagRecord(string $uid): void;
2127

2228
/**
2329
* Unflag record for deletion.
2430
* @param string $uid user id
2531
* @since 11.0.0
2632
*/
27-
public function unflagRecord($uid);
33+
public function unflagRecord(string $uid): void;
2834
}

0 commit comments

Comments
 (0)