Completed
Pull Request — master (#22620)
by Joas
09:42
created

CommentsEntityEvent   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 45
rs 10
c 2
b 0
f 0
wmc 4
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addEntityCollection() 0 7 2
A getEntityCollections() 0 3 1
1
<?php
2
/**
3
 * @author Joas Schilling <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2016, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCP\Comments;
23
24
use Symfony\Component\EventDispatcher\Event;
25
26
/**
27
 * Class CommentsEntityEvent
28
 *
29
 * @package OCP\Comments
30
 * @since 9.1.0
31
 */
32
class CommentsEntityEvent extends Event {
33
34
	const EVENT_ENTITY = 'OCP\Comments\ICommentsManager::registerEntity';
35
36
	/** @var string */
37
	protected $event;
38
	/** @var \Closure[] */
39
	protected $collections;
40
41
	/**
42
	 * DispatcherEvent constructor.
43
	 *
44
	 * @param string $event
45
	 * @since 9.1.0
46
	 */
47
	public function __construct($event) {
48
		$this->event = $event;
49
		$this->collections = [];
50
	}
51
52
	/**
53
	 * @param string $name
54
	 * @param \Closure $entityExistsFunction The closure should take one
55
	 *                 argument, which is the id of the entity, that comments
56
	 *                 should be handled for. The return should then be bool,
57
	 *                 depending on whether comments are allowed (true) or not.
58
	 * @throws \OutOfBoundsException when the entity name is already taken
59
	 * @since 9.1.0
60
	 */
61
	public function addEntityCollection($name, \Closure $entityExistsFunction) {
62
		if (isset($this->collections[$name])) {
63
			throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
64
		}
65
66
		$this->collections[$name] = $entityExistsFunction;
67
	}
68
69
	/**
70
	 * @return \Closure[]
71
	 * @since 9.1.0
72
	 */
73
	public function getEntityCollections() {
74
		return $this->collections;
75
	}
76
}
77