Passed
Push — master ( 2187f8...15d39c )
by Joas
11:45 queued 12s
created

GenericEntityEvent::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 10
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]>
5
 *
6
 * @author Arthur Schiwon <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCP\WorkflowEngine;
26
27
/**
28
 * Class GenericEntityEvent
29
 *
30
 * @package OCP\WorkflowEngine
31
 *
32
 * @since 18.0.0
33
 */
34
class GenericEntityEvent implements IEntityEvent {
35
36
	/** @var string */
37
	private $displayName;
38
	/** @var string */
39
	private $eventName;
40
41
	/**
42
	 * GenericEntityEvent constructor.
43
	 *
44
	 * @since 18.0.0
45
	 */
46
	public function __construct(string $displayName, string $eventName) {
47
		if(trim($displayName) === '') {
48
			throw new \InvalidArgumentException('DisplayName must not be empty');
49
		}
50
		if(trim($eventName) === '') {
51
			throw new \InvalidArgumentException('EventName must not be empty');
52
		}
53
54
		$this->displayName = trim($displayName);
55
		$this->eventName = trim($eventName);
56
	}
57
58
	/**
59
	 * returns a translated name to be presented in the web interface.
60
	 *
61
	 * Example: "created" (en), "kreita" (eo)
62
	 *
63
	 * @since 18.0.0
64
	 */
65
	public function getDisplayName(): string {
66
		return $this->displayName;
67
	}
68
69
	/**
70
	 * returns the event name that is emitted by the EventDispatcher, e.g.:
71
	 *
72
	 * Example: "OCA\MyApp\Factory\Cats::postCreated"
73
	 *
74
	 * @since 18.0.0
75
	 */
76
	public function getEventName(): string {
77
		return $this->eventName;
78
	}
79
}
80