Passed
Push — master ( 2f26ff...039ecb )
by Christoph
14:30 queued 10s
created

Event   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A stopPropagation() 0 2 1
A isPropagationStopped() 0 2 1
A __construct() 0 1 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright 2019 Christoph Wurst <[email protected]>
7
 *
8
 * @author Christoph Wurst <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCP\EventDispatcher;
28
29
use Psr\EventDispatcher\StoppableEventInterface;
30
31
/**
32
 * Base event class for the event dispatcher service
33
 *
34
 * Typically this class isn't instantiated directly but sub classed for specific
35
 * event types
36
 *
37
 * This class extended \Symfony\Contracts\EventDispatcher\Event until 21.0, since
38
 * 22.0.0 this class directly implements the PSR StoppableEventInterface and no
39
 * longer relies on Symfony. This transition does not come with any changes in API,
40
 * the class has the same methods and behavior before and after this change.
41
 *
42
 * @since 17.0.0
43
 */
44
class Event implements StoppableEventInterface {
45
46
	/**
47
	 * @var bool
48
	 *
49
	 * @since 22.0.0
50
	 */
51
	private $propagationStopped = false;
52
53
	/**
54
	 * Compatibility constructor
55
	 *
56
	 * In Nextcloud 17.0.0 this event class used a now deprecated/removed Symfony base
57
	 * class that had a constructor (with default arguments). To lower the risk of
58
	 * a breaking change (PHP won't allow parent constructor calls if there is none),
59
	 * this empty constructor's only purpose is to hopefully not break existing sub-
60
	 * classes of this class.
61
	 *
62
	 * @since 18.0.0
63
	 */
64
	public function __construct() {
65
	}
66
67
	/**
68
	 * Stops the propagation of the event to further event listeners
69
	 *
70
	 * @return void
71
	 *
72
	 * @since 22.0.0
73
	 */
74
	public function stopPropagation(): void {
75
		$this->propagationStopped = true;
76
	}
77
78
	/**
79
	 * {@inheritDoc}
80
	 *
81
	 * @since 22.0.0
82
	 * @see \Psr\EventDispatcher\StoppableEventInterface
83
	 */
84
	public function isPropagationStopped(): bool {
85
		return $this->propagationStopped;
86
	}
87
}
88