Skip to content

Commit

Permalink
Merge pull request #36592 from nextcloud/groupmanager-search-typing
Browse files Browse the repository at this point in the history
fix default values and type hints for GroupManager::search
  • Loading branch information
icewind1991 authored May 12, 2023
2 parents b83432f + 4a86487 commit 1f4dd62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
10 changes: 7 additions & 3 deletions lib/private/Group/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function getUserGroups($uid) {
*
* 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();
Expand All @@ -283,8 +283,12 @@ public function getGroups($search = '', $limit = null, $offset = null) {
)));
}

$query->setMaxResults($limit)
->setFirstResult($offset);
if ($limit > 0) {
$query->setMaxResults($limit);
}
if ($offset > 0) {
$query->setFirstResult($offset);
}
$result = $query->execute();

$groups = [];
Expand Down
8 changes: 4 additions & 4 deletions lib/private/Group/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ public function createGroup($gid) {

/**
* @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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/public/GroupInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getUserGroups($uid);
*
* 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
Expand Down
6 changes: 3 additions & 3 deletions lib/public/IGroupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ public function createGroup($gid);

/**
* @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
Expand Down

0 comments on commit 1f4dd62

Please sign in to comment.