Passed
Pull Request — master (#1307)
by René
03:59
created

Circle::getMembers()   A

Complexity

Conditions 6
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 12
c 3
b 0
f 0
dl 0
loc 16
rs 9.2222
cc 6
nc 2
nop 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
25
namespace OCA\Polls\Model;
26
27
use OCA\Circles\Api\v1\Circles;
0 ignored issues
show
Bug introduced by
The type OCA\Circles\Api\v1\Circles was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
29
use OCA\Polls\Exceptions\CirclesNotEnabledException;
30
31
class Circle extends UserGroupClass {
32
	public const TYPE = 'circle';
33
	public const ICON = 'icon-circles';
34
35
	private $circle;
36
37
	public function __construct(
38
		$id
39
	) {
40
		parent::__construct($id, self::TYPE);
41
		if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
42
			$this->icon = self::ICON;
43
			$this->circle = Circles::detailsCircle($id);
44
			$this->displayName = $this->circle->getName();
45
			$this->description = $this->circle->gettypeLongString();
46
		} else {
47
			throw new CirclesNotEnabledException();
48
		}
49
	}
50
51
	public static function isEnabled(): bool {
52
		return \OC::$server->getAppManager()->isEnabledForUser('circles');
53
	}
54
55
	/**
56
	 * @return Circle[]
57
	 */
58
	public static function search(string $query = '', $skip = []): array {
59
		$circles = [];
60
		if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
61
			foreach (Circles::listCircles(\OCA\Circles\Model\Circle::CIRCLES_ALL, $query) as $circle) {
0 ignored issues
show
Bug introduced by
The type OCA\Circles\Model\Circle was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
62
				if (!in_array($circle->getUniqueId(), $skip)) {
63
					$circles[] = new self($circle->getUniqueId());
64
				}
65
			}
66
		}
67
68
		return $circles;
69
	}
70
71
	/**
72
	 * @return User[]|Email[]|Contact[]
73
	 */
74
	public function getMembers() {
75
		$members = [];
76
		if (\OC::$server->getAppManager()->isEnabledForUser('circles')) {
77
			foreach (Circles::detailsCircle($this->id)->getMembers() as $circleMember) {
78
				if ($circleMember->getType() === Circles::TYPE_USER) {
79
					$members[] = new User($circleMember->getUserId());
80
				} elseif ($circleMember->getType() === Circles::TYPE_MAIL) {
81
					$members[] = new Email($circleMember->getUserId());
82
				} elseif ($circleMember->getType() === Circles::TYPE_CONTACT) {
83
					$members[] = new Contact($circleMember->getUserId());
84
				} else {
85
					continue;
86
				}
87
			}
88
		}
89
		return $members;
90
	}
91
}
92