diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2023-11-02 11:07:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 11:07:12 +0100 |
commit | d779092564297da2286631cb0dd381e585e635ee (patch) | |
tree | f4359e6fe506f07d93e50f478570e6cb5c626681 /lib | |
parent | 7c661895c3aae7558a54eaa9997563f59f59f2d4 (diff) | |
parent | 312dd8ac6dce96353ac1f6e6c89e0e7d7840d03c (diff) | |
download | nextcloud-server-d779092564297da2286631cb0dd381e585e635ee.tar.gz nextcloud-server-d779092564297da2286631cb0dd381e585e635ee.zip |
Merge pull request #38425 from nextcloud/feat/ocp/strict-igroup
feat(ocp): Add types and strict typing to \OCP\Group\IGroup
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Group/Group.php | 30 | ||||
-rw-r--r-- | lib/public/IGroup.php | 60 |
2 files changed, 48 insertions, 42 deletions
diff --git a/lib/private/Group/Group.php b/lib/private/Group/Group.php index 441ee64604d..97521d54ba6 100644 --- a/lib/private/Group/Group.php +++ b/lib/private/Group/Group.php @@ -85,11 +85,11 @@ class Group implements IGroup { $this->displayName = $displayName; } - public function getGID() { + public function getGID(): string { return $this->gid; } - public function getDisplayName() { + public function getDisplayName(): string { if (is_null($this->displayName)) { foreach ($this->backends as $backend) { if ($backend instanceof IGetDisplayNameBackend) { @@ -126,7 +126,7 @@ class Group implements IGroup { * * @return \OC\User\User[] */ - public function getUsers() { + public function getUsers(): array { if ($this->usersLoaded) { return $this->users; } @@ -153,7 +153,7 @@ class Group implements IGroup { * @param IUser $user * @return bool */ - public function inGroup(IUser $user) { + public function inGroup(IUser $user): bool { if (isset($this->users[$user->getUID()])) { return true; } @@ -171,7 +171,7 @@ class Group implements IGroup { * * @param IUser $user */ - public function addUser(IUser $user) { + public function addUser(IUser $user): void { if ($this->inGroup($user)) { return; } @@ -200,10 +200,8 @@ class Group implements IGroup { /** * remove a user from the group - * - * @param \OC\User\User $user */ - public function removeUser($user) { + public function removeUser(IUser $user): void { $result = false; $this->dispatcher->dispatchTyped(new BeforeUserRemovedEvent($this, $user)); if ($this->emitter) { @@ -262,7 +260,7 @@ class Group implements IGroup { * @param string $search * @return int|bool */ - public function count($search = '') { + public function count($search = ''): int|bool { $users = false; foreach ($this->backends as $backend) { if ($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) { @@ -282,7 +280,7 @@ class Group implements IGroup { * * @return int|bool */ - public function countDisabled() { + public function countDisabled(): int|bool { $users = false; foreach ($this->backends as $backend) { if ($backend instanceof ICountDisabledInGroup) { @@ -306,7 +304,7 @@ class Group implements IGroup { * @return IUser[] * @deprecated 27.0.0 Use searchUsers instead (same implementation) */ - public function searchDisplayName($search, $limit = null, $offset = null) { + public function searchDisplayName(string $search, int $limit = null, int $offset = null): array { return $this->searchUsers($search, $limit, $offset); } @@ -315,7 +313,7 @@ class Group implements IGroup { * * @return string[] */ - public function getBackendNames() { + public function getBackendNames(): array { $backends = []; foreach ($this->backends as $backend) { if ($backend instanceof INamedBackend) { @@ -329,11 +327,11 @@ class Group implements IGroup { } /** - * delete the group + * Delete the group * * @return bool */ - public function delete() { + public function delete(): bool { // Prevent users from deleting group admin if ($this->getGID() === 'admin') { return false; @@ -378,7 +376,7 @@ class Group implements IGroup { * @return bool * @since 14.0.0 */ - public function canRemoveUser() { + public function canRemoveUser(): bool { foreach ($this->backends as $backend) { if ($backend->implementsActions(GroupInterface::REMOVE_FROM_GOUP)) { return true; @@ -391,7 +389,7 @@ class Group implements IGroup { * @return bool * @since 14.0.0 */ - public function canAddUser() { + public function canAddUser(): bool { foreach ($this->backends as $backend) { if ($backend->implementsActions(GroupInterface::ADD_TO_GROUP)) { return true; diff --git a/lib/public/IGroup.php b/lib/public/IGroup.php index ec26cc55b69..51417641e26 100644 --- a/lib/public/IGroup.php +++ b/lib/public/IGroup.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -38,7 +41,7 @@ interface IGroup { * @return string * @since 8.0.0 */ - public function getGID(); + public function getGID(): string; /** * Returns the group display name @@ -46,7 +49,7 @@ interface IGroup { * @return string * @since 12.0.0 */ - public function getDisplayName(); + public function getDisplayName(): string; /** * Set the group display name @@ -60,43 +63,47 @@ interface IGroup { /** * get all users in the group * - * @return \OCP\IUser[] + * @return IUser[] * @since 8.0.0 */ - public function getUsers(); + public function getUsers(): array; /** * check if a user is in the group * - * @param \OCP\IUser $user + * @param IUser $user + * * @return bool * @since 8.0.0 */ - public function inGroup(IUser $user); + public function inGroup(IUser $user): bool; /** * add a user to the group * - * @param \OCP\IUser $user + * @param IUser $user + * * @since 8.0.0 */ - public function addUser(IUser $user); + public function addUser(IUser $user): void; /** - * remove a user from the group + * Remove a user from the group + * + * @param IUser $user * - * @param \OCP\IUser $user * @since 8.0.0 */ - public function removeUser($user); + public function removeUser(IUser $user): void; /** * search for users in the group by userid * * @param string $search - * @param int $limit - * @param int $offset - * @return \OCP\IUser[] + * @param int|null $limit + * @param int|null $offset + * + * @return IUser[] * @since 8.0.0 */ public function searchUsers(string $search, ?int $limit = null, ?int $offset = null): array; @@ -108,7 +115,7 @@ interface IGroup { * @return int|bool * @since 8.0.0 */ - public function count($search = ''); + public function count(string $search = ''): int|bool; /** * returns the number of disabled users @@ -116,18 +123,19 @@ interface IGroup { * @return int|bool * @since 14.0.0 */ - public function countDisabled(); + public function countDisabled(): int|bool; /** - * search for users in the group by displayname + * Search for users in the group by displayname * * @param string $search - * @param int $limit - * @param int $offset - * @return \OCP\IUser[] + * @param int|null $limit + * @param int|null $offset + * + * @return IUser[] * @since 8.0.0 */ - public function searchDisplayName($search, $limit = null, $offset = null); + public function searchDisplayName(string $search, int $limit = null, int $offset = null): array; /** * Get the names of the backends the group is connected to @@ -135,27 +143,27 @@ interface IGroup { * @return string[] * @since 22.0.0 */ - public function getBackendNames(); + public function getBackendNames(): array; /** - * delete the group + * Delete the group * * @return bool * @since 8.0.0 */ - public function delete(); + public function delete(): bool; /** * @return bool * @since 14.0.0 */ - public function canRemoveUser(); + public function canRemoveUser(): bool; /** * @return bool * @since 14.0.0 */ - public function canAddUser(); + public function canAddUser(): bool; /** * @return bool |