Completed
Push — master ( e6780c...89b6ee )
by Morris
33:24 queued 16:36
created

Manager::unregisterBackend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 3
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright 2018, 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 OC\Calendar\Room;
25
26
use OCP\Calendar\Room\IBackend;
27
28 View Code Duplication
class Manager implements \OCP\Calendar\Room\IManager {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
30
	/** @var IBackend[] holds all registered resource backends */
31
	private $backends;
32
33
	/**
34
	 * Registers a resource backend
35
	 *
36
	 * @param IBackend $backend
37
	 * @return void
38
	 * @since 14.0.0
39
	 */
40
	public function registerBackend(IBackend $backend) {
41
		$this->backends[$backend->getBackendIdentifier()] = $backend;
42
	}
43
44
	/**
45
	 * Unregisters a resource backend
46
	 *
47
	 * @param IBackend $backend
48
	 * @return void
49
	 * @since 14.0.0
50
	 */
51
	public function unregisterBackend(IBackend $backend) {
52
		unset($this->backends[$backend->getBackendIdentifier()]);
53
	}
54
55
	/**
56
	 * @return IBackend[]
57
	 * @since 14.0.0
58
	 */
59
	public function getBackends():array {
60
		return array_values($this->backends);
61
	}
62
63
	/**
64
	 * @param string $backendId
65
	 * @return IBackend|null
66
	 */
67
	public function getBackend($backendId):IBackend {
68
		if (!isset($this->backends[$backendId])) {
69
			return null;
70
		}
71
72
		return $this->backends[$backendId];
73
	}
74
75
	/**
76
	 * removes all registered backend instances
77
	 * @return void
78
	 * @since 14.0.0
79
	 */
80
	public function clear() {
81
		$this->backends = [];
82
	}
83
}
84