Skip to content

Commit d98fbf1

Browse files
feat(ocp): Add types and strict typing to \OCP\Group\IGroup
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 7ec1ceb commit d98fbf1

2 files changed

Lines changed: 48 additions & 42 deletions

File tree

lib/private/Group/Group.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ public function __construct(string $gid, array $backends, EventDispatcherInterfa
8989
$this->displayName = $displayName;
9090
}
9191

92-
public function getGID() {
92+
public function getGID(): string {
9393
return $this->gid;
9494
}
9595

96-
public function getDisplayName() {
96+
public function getDisplayName(): string {
9797
if (is_null($this->displayName)) {
9898
foreach ($this->backends as $backend) {
9999
if ($backend instanceof IGetDisplayNameBackend) {
@@ -130,7 +130,7 @@ public function setDisplayName(string $displayName): bool {
130130
*
131131
* @return \OC\User\User[]
132132
*/
133-
public function getUsers() {
133+
public function getUsers(): array {
134134
if ($this->usersLoaded) {
135135
return $this->users;
136136
}
@@ -157,7 +157,7 @@ public function getUsers() {
157157
* @param IUser $user
158158
* @return bool
159159
*/
160-
public function inGroup(IUser $user) {
160+
public function inGroup(IUser $user): bool {
161161
if (isset($this->users[$user->getUID()])) {
162162
return true;
163163
}
@@ -175,7 +175,7 @@ public function inGroup(IUser $user) {
175175
*
176176
* @param IUser $user
177177
*/
178-
public function addUser(IUser $user) {
178+
public function addUser(IUser $user): void {
179179
if ($this->inGroup($user)) {
180180
return;
181181
}
@@ -208,10 +208,8 @@ public function addUser(IUser $user) {
208208

209209
/**
210210
* remove a user from the group
211-
*
212-
* @param \OC\User\User $user
213211
*/
214-
public function removeUser($user) {
212+
public function removeUser(IUser $user): void {
215213
$result = false;
216214
$this->dispatcher->dispatch(IGroup::class . '::preRemoveUser', new GenericEvent($this, [
217215
'user' => $user,
@@ -274,7 +272,7 @@ public function searchUsers(string $search, ?int $limit = null, ?int $offset = n
274272
* @param string $search
275273
* @return int|bool
276274
*/
277-
public function count($search = '') {
275+
public function count($search = ''): int|bool {
278276
$users = false;
279277
foreach ($this->backends as $backend) {
280278
if ($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) {
@@ -294,7 +292,7 @@ public function count($search = '') {
294292
*
295293
* @return int|bool
296294
*/
297-
public function countDisabled() {
295+
public function countDisabled(): int|bool {
298296
$users = false;
299297
foreach ($this->backends as $backend) {
300298
if ($backend instanceof ICountDisabledInGroup) {
@@ -318,7 +316,7 @@ public function countDisabled() {
318316
* @return IUser[]
319317
* @deprecated 27.0.0 Use searchUsers instead (same implementation)
320318
*/
321-
public function searchDisplayName($search, $limit = null, $offset = null) {
319+
public function searchDisplayName(string $search, int $limit = null, int $offset = null): array {
322320
return $this->searchUsers($search, $limit, $offset);
323321
}
324322

@@ -327,7 +325,7 @@ public function searchDisplayName($search, $limit = null, $offset = null) {
327325
*
328326
* @return string[]
329327
*/
330-
public function getBackendNames() {
328+
public function getBackendNames(): array {
331329
$backends = [];
332330
foreach ($this->backends as $backend) {
333331
if ($backend instanceof INamedBackend) {
@@ -341,11 +339,11 @@ public function getBackendNames() {
341339
}
342340

343341
/**
344-
* delete the group
342+
* Delete the group
345343
*
346344
* @return bool
347345
*/
348-
public function delete() {
346+
public function delete(): bool {
349347
// Prevent users from deleting group admin
350348
if ($this->getGID() === 'admin') {
351349
return false;
@@ -390,7 +388,7 @@ private function getVerifiedUsers(array $userIds): array {
390388
* @return bool
391389
* @since 14.0.0
392390
*/
393-
public function canRemoveUser() {
391+
public function canRemoveUser(): bool {
394392
foreach ($this->backends as $backend) {
395393
if ($backend->implementsActions(GroupInterface::REMOVE_FROM_GOUP)) {
396394
return true;
@@ -403,7 +401,7 @@ public function canRemoveUser() {
403401
* @return bool
404402
* @since 14.0.0
405403
*/
406-
public function canAddUser() {
404+
public function canAddUser(): bool {
407405
foreach ($this->backends as $backend) {
408406
if ($backend->implementsActions(GroupInterface::ADD_TO_GROUP)) {
409407
return true;

lib/public/IGroup.php

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2016, ownCloud, Inc.
47
*
@@ -38,15 +41,15 @@ interface IGroup {
3841
* @return string
3942
* @since 8.0.0
4043
*/
41-
public function getGID();
44+
public function getGID(): string;
4245

4346
/**
4447
* Returns the group display name
4548
*
4649
* @return string
4750
* @since 12.0.0
4851
*/
49-
public function getDisplayName();
52+
public function getDisplayName(): string;
5053

5154
/**
5255
* Set the group display name
@@ -60,43 +63,47 @@ public function setDisplayName(string $displayName): bool;
6063
/**
6164
* get all users in the group
6265
*
63-
* @return \OCP\IUser[]
66+
* @return IUser[]
6467
* @since 8.0.0
6568
*/
66-
public function getUsers();
69+
public function getUsers(): array;
6770

6871
/**
6972
* check if a user is in the group
7073
*
71-
* @param \OCP\IUser $user
74+
* @param IUser $user
75+
*
7276
* @return bool
7377
* @since 8.0.0
7478
*/
75-
public function inGroup(IUser $user);
79+
public function inGroup(IUser $user): bool;
7680

7781
/**
7882
* add a user to the group
7983
*
80-
* @param \OCP\IUser $user
84+
* @param IUser $user
85+
*
8186
* @since 8.0.0
8287
*/
83-
public function addUser(IUser $user);
88+
public function addUser(IUser $user): void;
8489

8590
/**
86-
* remove a user from the group
91+
* Remove a user from the group
92+
*
93+
* @param IUser $user
8794
*
88-
* @param \OCP\IUser $user
8995
* @since 8.0.0
9096
*/
91-
public function removeUser($user);
97+
public function removeUser(IUser $user): void;
9298

9399
/**
94100
* search for users in the group by userid
95101
*
96102
* @param string $search
97-
* @param int $limit
98-
* @param int $offset
99-
* @return \OCP\IUser[]
103+
* @param int|null $limit
104+
* @param int|null $offset
105+
*
106+
* @return IUser[]
100107
* @since 8.0.0
101108
*/
102109
public function searchUsers(string $search, ?int $limit = null, ?int $offset = null): array;
@@ -108,54 +115,55 @@ public function searchUsers(string $search, ?int $limit = null, ?int $offset = n
108115
* @return int|bool
109116
* @since 8.0.0
110117
*/
111-
public function count($search = '');
118+
public function count(string $search = ''): int|bool;
112119

113120
/**
114121
* returns the number of disabled users
115122
*
116123
* @return int|bool
117124
* @since 14.0.0
118125
*/
119-
public function countDisabled();
126+
public function countDisabled(): int|bool;
120127

121128
/**
122-
* search for users in the group by displayname
129+
* Search for users in the group by displayname
123130
*
124131
* @param string $search
125-
* @param int $limit
126-
* @param int $offset
127-
* @return \OCP\IUser[]
132+
* @param int|null $limit
133+
* @param int|null $offset
134+
*
135+
* @return IUser[]
128136
* @since 8.0.0
129137
*/
130-
public function searchDisplayName($search, $limit = null, $offset = null);
138+
public function searchDisplayName(string $search, int $limit = null, int $offset = null): array;
131139

132140
/**
133141
* Get the names of the backends the group is connected to
134142
*
135143
* @return string[]
136144
* @since 22.0.0
137145
*/
138-
public function getBackendNames();
146+
public function getBackendNames(): array;
139147

140148
/**
141-
* delete the group
149+
* Delete the group
142150
*
143151
* @return bool
144152
* @since 8.0.0
145153
*/
146-
public function delete();
154+
public function delete(): bool;
147155

148156
/**
149157
* @return bool
150158
* @since 14.0.0
151159
*/
152-
public function canRemoveUser();
160+
public function canRemoveUser(): bool;
153161

154162
/**
155163
* @return bool
156164
* @since 14.0.0
157165
*/
158-
public function canAddUser();
166+
public function canAddUser(): bool;
159167

160168
/**
161169
* @return bool

0 commit comments

Comments
 (0)