Completed
Pull Request — master (#384)
by Tortue
02:31
created

LocalGroups::search()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.9777
c 0
b 0
f 0
cc 6
nc 3
nop 1
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Search;
28
29
use OC;
30
use OCA\Circles\ISearch;
31
use OCA\Circles\Model\Member;
32
use OCA\Circles\Model\SearchResult;
33
use OCP\IUser;
34
use OCA\Circles\Service\ConfigService;
35
36
class LocalGroups implements ISearch {
37
38
	/** @var ConfigService */
39
	private $configService;
40
41
	/**
42
	 * @param ConfigService $configService
43
	 */
44
	public function __construct(ConfigService $configService)
45
	{
46
		$this->configService = $configService;
47
	}
48
49
	/**
50
	 * {@inheritdoc}
51
	 */
52
	public function search($search) {
53
54
		$result = [];
55
		$groupManager = OC::$server->getGroupManager();
56
57
		$groups = $groupManager->search($search);
58
		$user = OC::$server->getUserSession()->getUser();
59
		foreach ($groups as $group) {
60
			if ($this->configService->isAddingAnyGroupMembersAllowed() ||
61
				(
62
					$user instanceof IUser &&
0 ignored issues
show
Bug introduced by
The class OCP\IUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
63
					($group->inGroup($user) || $groupManager->isAdmin($user->getUID()))
64
				)
65
			) {
66
				$result[] = new SearchResult($group->getGID(), Member::TYPE_GROUP);
67
			}
68
		}
69
70
		return $result;
71
	}
72
73
}
74