Completed
Pull Request — master (#546)
by Maxence
01:58
created

CircleService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 64
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setLocalViewer() 0 3 1
A setViewer() 0 3 1
A getViewer() 0 3 1
A getCircles() 0 3 1
A getCircle() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
6
/**
7
 * Circles - Bring cloud-users closer together.
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later. See the COPYING file.
11
 *
12
 * @author Maxence Lange <[email protected]>
13
 * @copyright 2021
14
 * @license GNU AGPL version 3 or any later version
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 *
29
 */
30
31
32
namespace OCA\Circles\Service;
33
34
35
use daita\MySmallPhpTools\Traits\TArrayTools;
36
use OCA\Circles\Db\CircleRequest;
37
use OCA\Circles\Exceptions\CircleNotFoundException;
38
use OCA\Circles\Model\Circle;
39
use OCA\Circles\Model\Member;
40
41
42
/**
43
 * Class CircleService
44
 *
45
 * @package OCA\Circles\Service
46
 */
47
class CircleService {
48
49
50
	use TArrayTools;
51
52
53
	/** @var CircleRequest */
54
	private $circleRequest;
55
56
57
	/** @var Member */
58
	private $viewer = null;
59
60
61
	/**
62
	 * CircleService constructor.
63
	 *
64
	 * @param CircleRequest $circleRequest
65
	 */
66
	public function __construct(CircleRequest $circleRequest) {
67
		$this->circleRequest = $circleRequest;
68
	}
69
70
71
	/**
72
	 * @param string $userId
73
	 */
74
	public function setLocalViewer(string $userId): void {
75
		$this->viewer = new Member($userId, Member::TYPE_USER, '');
76
	}
77
78
	public function setViewer(Member $viewer): void {
79
		$this->viewer = $viewer;
80
	}
81
82
	/**
83
	 * @return Member|null
84
	 */
85
	public function getViewer(): ?Member {
86
		return $this->viewer;
87
	}
88
89
90
	/**
91
	 * @param Member|null $filter
92
	 *
93
	 * @return Circle[]
94
	 */
95
	public function getCircles(?Member $filter = null): array {
96
		return $this->circleRequest->getCircles($filter, $this->getViewer());
97
	}
98
99
100
	/**
101
	 * @param string $circleId
102
	 *
103
	 * @return Circle
104
	 * @throws CircleNotFoundException
105
	 */
106
	public function getCircle(string $circleId): Circle {
107
		return $this->circleRequest->getCircle($circleId, $this->getViewer());
108
	}
109
110
}
111
112