Merge pull request #36592 from nextcloud/groupmanager-search-typing

fix default values and type hints for GroupManager::search
This commit is contained in:
Robin Appelman 2023-05-12 15:25:32 +02:00 committed by GitHub
commit 1f4dd62b4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 11 deletions

View file

@ -266,7 +266,7 @@ class Database extends ABackend implements
*
* Returns a list with all groups
*/
public function getGroups($search = '', $limit = null, $offset = null) {
public function getGroups(string $search = '', int $limit = -1, int $offset = 0) {
$this->fixDI();
$query = $this->dbConn->getQueryBuilder();
@ -283,8 +283,12 @@ class Database extends ABackend implements
)));
}
$query->setMaxResults($limit)
->setFirstResult($offset);
if ($limit > 0) {
$query->setMaxResults($limit);
}
if ($offset > 0) {
$query->setFirstResult($offset);
}
$result = $query->execute();
$groups = [];

View file

@ -236,14 +236,14 @@ class Manager extends PublicEmitter implements IGroupManager {
/**
* @param string $search
* @param int $limit
* @param int $offset
* @param ?int $limit
* @param ?int $offset
* @return \OC\Group\Group[]
*/
public function search($search, $limit = null, $offset = null) {
public function search(string $search, ?int $limit = null, ?int $offset = 0) {
$groups = [];
foreach ($this->backends as $backend) {
$groupIds = $backend->getGroups($search, $limit, $offset);
$groupIds = $backend->getGroups($search, $limit ?? -1, $offset ?? 0);
foreach ($groupIds as $groupId) {
$aGroup = $this->get($groupId);
if ($aGroup instanceof IGroup) {

View file

@ -95,7 +95,7 @@ interface GroupInterface {
*
* Returns a list with all groups
*/
public function getGroups($search = '', $limit = -1, $offset = 0);
public function getGroups(string $search = '', int $limit = -1, int $offset = 0);
/**
* check if a group exists

View file

@ -96,12 +96,12 @@ interface IGroupManager {
/**
* @param string $search
* @param int $limit
* @param int $offset
* @param ?int $limit
* @param ?int $offset
* @return \OCP\IGroup[]
* @since 8.0.0
*/
public function search($search, $limit = null, $offset = null);
public function search(string $search, ?int $limit = null, ?int $offset = 0);
/**
* @param \OCP\IUser|null $user