Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ocp): Add types and strict typing to \OCP\Group\IGroup #38425

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions lib/private/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public function __construct(string $gid, array $backends, IEventDispatcher $disp
$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) {
Expand Down Expand Up @@ -126,7 +126,7 @@ public function setDisplayName(string $displayName): bool {
*
* @return \OC\User\User[]
*/
public function getUsers() {
public function getUsers(): array {
if ($this->usersLoaded) {
return $this->users;
}
Expand All @@ -153,7 +153,7 @@ public function getUsers() {
* @param IUser $user
* @return bool
*/
public function inGroup(IUser $user) {
public function inGroup(IUser $user): bool {
if (isset($this->users[$user->getUID()])) {
return true;
}
Expand All @@ -171,7 +171,7 @@ public function inGroup(IUser $user) {
*
* @param IUser $user
*/
public function addUser(IUser $user) {
public function addUser(IUser $user): void {
if ($this->inGroup($user)) {
return;
}
Expand Down Expand Up @@ -200,10 +200,8 @@ public function addUser(IUser $user) {

/**
* 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) {
Expand Down Expand Up @@ -262,7 +260,7 @@ public function searchUsers(string $search, ?int $limit = null, ?int $offset = n
* @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)) {
Expand All @@ -282,7 +280,7 @@ public function count($search = '') {
*
* @return int|bool
*/
public function countDisabled() {
public function countDisabled(): int|bool {
$users = false;
foreach ($this->backends as $backend) {
if ($backend instanceof ICountDisabledInGroup) {
Expand All @@ -306,7 +304,7 @@ public function countDisabled() {
* @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);
}

Expand All @@ -315,7 +313,7 @@ public function searchDisplayName($search, $limit = null, $offset = null) {
*
* @return string[]
*/
public function getBackendNames() {
public function getBackendNames(): array {
$backends = [];
foreach ($this->backends as $backend) {
if ($backend instanceof INamedBackend) {
Expand All @@ -329,11 +327,11 @@ public function getBackendNames() {
}

/**
* 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;
Expand Down Expand Up @@ -378,7 +376,7 @@ private function getVerifiedUsers(array $userIds): array {
* @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;
Expand All @@ -391,7 +389,7 @@ public function canRemoveUser() {
* @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;
Expand Down
60 changes: 34 additions & 26 deletions lib/public/IGroup.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
Expand Down Expand Up @@ -38,15 +41,15 @@ interface IGroup {
* @return string
* @since 8.0.0
*/
public function getGID();
public function getGID(): string;

/**
* Returns the group display name
*
* @return string
* @since 12.0.0
*/
public function getDisplayName();
public function getDisplayName(): string;

/**
* Set the group display name
Expand All @@ -60,43 +63,47 @@ public function setDisplayName(string $displayName): bool;
/**
* 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;
Expand All @@ -108,54 +115,55 @@ public function searchUsers(string $search, ?int $limit = null, ?int $offset = n
* @return int|bool
* @since 8.0.0
*/
public function count($search = '');
public function count(string $search = ''): int|bool;

/**
* returns the number of disabled users
*
* @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
*
* @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
Expand Down
Loading