Skip to content

Commit b6c17c6

Browse files
committed
Clear up return types
usersInGroup index by int for BC, searchInGroup index by uid (string). Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 6385a5a commit b6c17c6

File tree

10 files changed

+21
-16
lines changed

10 files changed

+21
-16
lines changed

apps/user_ldap/lib/Access.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ public function mapAndAnnounceIfApplicable(
631631
* gives back the user names as they are used ownClod internally
632632
*
633633
* @param array $ldapUsers as returned by fetchList()
634-
* @return array an array with the user names to use in Nextcloud
634+
* @return array<int,string> an array with the user names to use in Nextcloud
635635
*
636636
* gives back the user names as they are used ownClod internally
637637
* @throws \Exception
@@ -644,7 +644,7 @@ public function nextcloudUserNames($ldapUsers) {
644644
* gives back the group names as they are used ownClod internally
645645
*
646646
* @param array $ldapGroups as returned by fetchList()
647-
* @return array an array with the group names to use in Nextcloud
647+
* @return array<int,string> an array with the group names to use in Nextcloud
648648
*
649649
* gives back the group names as they are used ownClod internally
650650
* @throws \Exception
@@ -655,6 +655,7 @@ public function nextcloudGroupNames($ldapGroups) {
655655

656656
/**
657657
* @param array[] $ldapObjects as returned by fetchList()
658+
* @return array<int,string>
658659
* @throws \Exception
659660
*/
660661
private function ldap2NextcloudNames(array $ldapObjects, bool $isUsers): array {

apps/user_ldap/lib/Group_LDAP.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ private function prepareFilterForUsersHasGidNumber(string $groupDN, string $sear
466466
}
467467

468468
/**
469-
* @return array A list of users that have the given group as gid number
469+
* @return array<int,string> A list of users that have the given group as gid number
470470
* @throws ServerNotAvailableException
471471
*/
472472
public function getUsersInGidNumber(
@@ -591,6 +591,7 @@ private function prepareFilterForUsersInPrimaryGroup(string $groupDN, string $se
591591

592592
/**
593593
* @throws ServerNotAvailableException
594+
* @return array<int,string>
594595
*/
595596
public function getUsersInPrimaryGroup(
596597
string $groupDN,
@@ -840,7 +841,7 @@ private function getGroupsByMember(string $dn, array &$seen = []): array {
840841
* @param string $search
841842
* @param int $limit
842843
* @param int $offset
843-
* @return array with user ids
844+
* @return array<int,string> user ids
844845
* @throws Exception
845846
* @throws ServerNotAvailableException
846847
*/
@@ -909,7 +910,11 @@ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
909910
if (empty($ldap_users)) {
910911
break;
911912
}
912-
$groupUsers[] = $this->access->dn2username($ldap_users[0]['dn'][0]);
913+
$uid = $this->access->dn2username($ldap_users[0]['dn'][0]);
914+
if (!$uid) {
915+
break;
916+
}
917+
$groupUsers[] = $uid;
913918
break;
914919
default:
915920
//we got DNs, check if we need to filter by search or we can give back all of them

apps/user_ldap/lib/Group_Proxy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function getUserGroups($uid) {
171171
/**
172172
* get a list of all users in a group
173173
*
174-
* @return string[] with user ids
174+
* @return array<int,string> user ids
175175
*/
176176
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
177177
$this->setup();

lib/private/Group/Backend.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function groupExists($gid) {
126126
* @param string $search
127127
* @param int $limit
128128
* @param int $offset
129-
* @return array an array of user ids
129+
* @return array<int,string> an array of user ids
130130
*/
131131
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
132132
return [];

lib/private/Group/Database.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ public function groupExists($gid) {
333333
* @param string $search
334334
* @param int $limit
335335
* @param int $offset
336-
* @return array<string> an array of user ids
336+
* @return array<int,string> an array of user ids
337337
*/
338338
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0): array {
339-
return array_map(fn ($user) => $user->getUid(), $this->searchInGroup($gid, $search, $limit, $offset));
339+
return array_values(array_map(fn ($user) => $user->getUid(), $this->searchInGroup($gid, $search, $limit, $offset)));
340340
}
341341

342342
public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array {

lib/private/Group/Group.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public function searchUsers(string $search, ?int $limit = null, ?int $offset = n
251251
$users = [];
252252
foreach ($this->backends as $backend) {
253253
if ($backend instanceof ISearchableGroupBackend) {
254-
$users = array_merge($users, $backend->searchInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0));
254+
$users = array_merge($users, array_values($backend->searchInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0)));
255255
} else {
256256
$userIds = $backend->usersInGroup($this->gid, $search, $limit ?? -1, $offset ?? 0);
257257
$userManager = \OCP\Server::get(IUserManager::class);

lib/public/Group/Backend/ISearchableGroupBackend.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* @since 26.0.0
3030
*/
3131
interface ISearchableGroupBackend {
32-
3332
/**
3433
* @brief Get a list of users matching the given search parameters.
3534
*
@@ -45,7 +44,7 @@ interface ISearchableGroupBackend {
4544
* want to search. This can be empty to get all the users.
4645
* @param int $limit The limit of results
4746
* @param int $offset The offset of the results
48-
* @return IUser[]
47+
* @return array<string,IUser> Users indexed by uid
4948
* @since 26.0.0
5049
*/
5150
public function searchInGroup(string $gid, string $search = '', int $limit = -1, int $offset = 0): array;

lib/public/GroupInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function groupExists($gid);
112112
* @param string $search
113113
* @param int $limit
114114
* @param int $offset
115-
* @return array an array of user ids
115+
* @return array<int,string> an array of user ids
116116
* @since 4.5.0
117117
* @deprecated 26.0.0 Use searchInGroup instead, for performance reasons
118118
*/

tests/lib/Group/ManagerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmpty() {
737737
$backend->expects($this->once())
738738
->method('searchInGroup')
739739
->with('testgroup', '', -1, 0)
740-
->willReturn([$this->getTestUser('user2'), $this->getTestUser('user33')]);
740+
->willReturn(['user2' => $this->getTestUser('user2'), 'user33' => $this->getTestUser('user33')]);
741741

742742
$this->userManager->expects($this->never())->method('get');
743743

@@ -793,7 +793,7 @@ public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitA
793793
$backend->expects($this->once())
794794
->method('searchInGroup')
795795
->with('testgroup', '', 1, 1)
796-
->willReturn([$this->getTestUser('user33')]);
796+
->willReturn(['user33' => $this->getTestUser('user33')]);
797797

798798
$this->userManager->expects($this->never())->method('get');
799799

tests/lib/Util/Group/Dummy.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function searchInGroup(string $gid, string $search = '', int $limit = -1,
208208
$result = [];
209209
foreach ($this->groups[$gid] as $user) {
210210
if (stripos($user, $search) !== false) {
211-
$result[] = new DummyUser($user, '');
211+
$result[$user] = new DummyUser($user, '');
212212
}
213213
}
214214
return $result;

0 commit comments

Comments
 (0)