Merge pull request #38425 from nextcloud/feat/ocp/strict-igroup

feat(ocp): Add types and strict typing to \OCP\Group\IGroup
This commit is contained in:
Christoph Wurst 2023-11-02 11:07:12 +01:00 committed by GitHub
commit d779092564
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 42 deletions

View file

@ -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;

View file

@ -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