Passed
Pull Request — master (#1545)
by Julius
03:01
created

CalendarPlugin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getAppId() 0 3 1
A fetchAllForCalendarHome() 0 6 1
A hasCalendarInCalendarHome() 0 6 1
A getCalendarInCalendarHome() 0 8 2
1
<?php
2
/**
3
 * @copyright 2020, Georg Ehrke <[email protected]>
4
 *
5
 * @author Georg Ehrke <[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
namespace OCA\Deck\DAV;
25
26
use OCA\DAV\CalDAV\Integration\ExternalCalendar;
27
use OCA\DAV\CalDAV\Integration\ICalendarProvider;
28
use OCA\Deck\Db\Board;
29
use OCA\Deck\Service\BoardService;
30
31
class CalendarPlugin implements ICalendarProvider {
32
33
	/**
34
	 * @var BoardService
35
	 */
36
	private $boardService;
37
38
	public function __construct(BoardService $boardService) {
39
		$this->boardService = $boardService;
40
	}
41
42
	/**
43
	 * @inheritDoc
44
	 */
45
	public function getAppId(): string {
46
		return 'deck';
47
	}
48
49
	/**
50
	 * @inheritDoc
51
	 */
52
	public function fetchAllForCalendarHome(string $principalUri): array {
53
		$boards = $this->boardService->findAll();
54
		return array_map(function (Board $board) use ($principalUri) {
55
			return new Calendar($principalUri, 'board-' . $board->getId(), $board);
56
		}, $boards);
57
	}
58
59
	/**
60
	 * @inheritDoc
61
	 */
62
	public function hasCalendarInCalendarHome(string $principalUri, string $calendarUri): bool {
63
		$boards = array_map(function(Board $board) {
64
			return 'board-' . $board->getId();
65
		}, $this->boardService->findAll());
66
		return in_array($calendarUri, $boards, true);
67
	}
68
69
	/**
70
	 * @inheritDoc
71
	 */
72
	public function getCalendarInCalendarHome(string $principalUri, string $calendarUri): ?ExternalCalendar {
73
		if ($this->hasCalendarInCalendarHome($principalUri, $calendarUri)) {
74
			$board = $this->boardService->find(str_replace('board-', '', $calendarUri));
75
			return new Calendar($principalUri, $calendarUri, $board);
76
		}
77
78
		return null;
79
	}
80
}
81