Passed
Push — master ( 8eda51...dcde97 )
by Christoph
17:12 queued 12s
created
lib/private/EventDispatcher/GenericEventWrapper.php 2 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -30,95 +30,95 @@
 block discarded – undo
30 30
 use Symfony\Component\EventDispatcher\GenericEvent;
31 31
 
32 32
 class GenericEventWrapper extends GenericEvent {
33
-	private LoggerInterface $logger;
34
-
35
-	/** @var GenericEvent */
36
-	private $event;
37
-
38
-	/** @var string */
39
-	private $eventName;
40
-
41
-	/** @var bool */
42
-	private $deprecationNoticeLogged = false;
43
-
44
-	public function __construct(LoggerInterface $logger, string $eventName, ?GenericEvent $event) {
45
-		parent::__construct($eventName);
46
-		$this->logger = $logger;
47
-		$this->event = $event;
48
-		$this->eventName = $eventName;
49
-	}
50
-
51
-	private function log() {
52
-		if ($this->deprecationNoticeLogged) {
53
-			return;
54
-		}
55
-
56
-		$class = ($this->event !== null && is_object($this->event)) ? get_class($this->event) : 'null';
57
-		$this->logger->debug(
58
-			'Deprecated event type for {name}: {class} is used',
59
-			[ 'name' => $this->eventName, 'class' => $class]
60
-		);
61
-		$this->deprecationNoticeLogged = true;
62
-	}
63
-
64
-	public function isPropagationStopped(): bool {
65
-		$this->log();
66
-		return $this->event->isPropagationStopped();
67
-	}
68
-
69
-	public function stopPropagation(): void {
70
-		$this->log();
71
-		$this->event->stopPropagation();
72
-	}
73
-
74
-	public function getSubject() {
75
-		$this->log();
76
-		return $this->event->getSubject();
77
-	}
78
-
79
-	public function getArgument($key) {
80
-		$this->log();
81
-		return $this->event->getArgument($key);
82
-	}
83
-
84
-	public function setArgument($key, $value) {
85
-		$this->log();
86
-		return $this->event->setArgument($key, $value);
87
-	}
88
-
89
-	public function getArguments() {
90
-		return $this->event->getArguments();
91
-	}
92
-
93
-	public function setArguments(array $args = []) {
94
-		return $this->event->setArguments($args);
95
-	}
96
-
97
-	public function hasArgument($key) {
98
-		return $this->event->hasArgument($key);
99
-	}
100
-
101
-	/**
102
-	 * @return mixed
103
-	 */
104
-	#[\ReturnTypeWillChange]
105
-	public function offsetGet($key) {
106
-		return $this->event->offsetGet($key);
107
-	}
108
-
109
-	public function offsetSet($key, $value): void {
110
-		$this->event->offsetSet($key, $value);
111
-	}
112
-
113
-	public function offsetUnset($key): void {
114
-		$this->event->offsetUnset($key);
115
-	}
116
-
117
-	public function offsetExists($key): bool {
118
-		return $this->event->offsetExists($key);
119
-	}
120
-
121
-	public function getIterator() {
122
-		return$this->event->getIterator();
123
-	}
33
+    private LoggerInterface $logger;
34
+
35
+    /** @var GenericEvent */
36
+    private $event;
37
+
38
+    /** @var string */
39
+    private $eventName;
40
+
41
+    /** @var bool */
42
+    private $deprecationNoticeLogged = false;
43
+
44
+    public function __construct(LoggerInterface $logger, string $eventName, ?GenericEvent $event) {
45
+        parent::__construct($eventName);
46
+        $this->logger = $logger;
47
+        $this->event = $event;
48
+        $this->eventName = $eventName;
49
+    }
50
+
51
+    private function log() {
52
+        if ($this->deprecationNoticeLogged) {
53
+            return;
54
+        }
55
+
56
+        $class = ($this->event !== null && is_object($this->event)) ? get_class($this->event) : 'null';
57
+        $this->logger->debug(
58
+            'Deprecated event type for {name}: {class} is used',
59
+            [ 'name' => $this->eventName, 'class' => $class]
60
+        );
61
+        $this->deprecationNoticeLogged = true;
62
+    }
63
+
64
+    public function isPropagationStopped(): bool {
65
+        $this->log();
66
+        return $this->event->isPropagationStopped();
67
+    }
68
+
69
+    public function stopPropagation(): void {
70
+        $this->log();
71
+        $this->event->stopPropagation();
72
+    }
73
+
74
+    public function getSubject() {
75
+        $this->log();
76
+        return $this->event->getSubject();
77
+    }
78
+
79
+    public function getArgument($key) {
80
+        $this->log();
81
+        return $this->event->getArgument($key);
82
+    }
83
+
84
+    public function setArgument($key, $value) {
85
+        $this->log();
86
+        return $this->event->setArgument($key, $value);
87
+    }
88
+
89
+    public function getArguments() {
90
+        return $this->event->getArguments();
91
+    }
92
+
93
+    public function setArguments(array $args = []) {
94
+        return $this->event->setArguments($args);
95
+    }
96
+
97
+    public function hasArgument($key) {
98
+        return $this->event->hasArgument($key);
99
+    }
100
+
101
+    /**
102
+     * @return mixed
103
+     */
104
+    #[\ReturnTypeWillChange]
105
+    public function offsetGet($key) {
106
+        return $this->event->offsetGet($key);
107
+    }
108
+
109
+    public function offsetSet($key, $value): void {
110
+        $this->event->offsetSet($key, $value);
111
+    }
112
+
113
+    public function offsetUnset($key): void {
114
+        $this->event->offsetUnset($key);
115
+    }
116
+
117
+    public function offsetExists($key): bool {
118
+        return $this->event->offsetExists($key);
119
+    }
120
+
121
+    public function getIterator() {
122
+        return$this->event->getIterator();
123
+    }
124 124
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
 		$class = ($this->event !== null && is_object($this->event)) ? get_class($this->event) : 'null';
57 57
 		$this->logger->debug(
58 58
 			'Deprecated event type for {name}: {class} is used',
59
-			[ 'name' => $this->eventName, 'class' => $class]
59
+			['name' => $this->eventName, 'class' => $class]
60 60
 		);
61 61
 		$this->deprecationNoticeLogged = true;
62 62
 	}
Please login to merge, or discard this patch.
lib/private/EventDispatcher/SymfonyAdapter.php 1 patch
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -40,170 +40,170 @@
 block discarded – undo
40 40
  * @deprecated 20.0.0 use \OCP\EventDispatcher\IEventDispatcher
41 41
  */
42 42
 class SymfonyAdapter implements EventDispatcherInterface {
43
-	/** @var EventDispatcher */
44
-	private $eventDispatcher;
45
-	private LoggerInterface $logger;
46
-
47
-	/**
48
-	 * @deprecated 20.0.0
49
-	 */
50
-	public function __construct(EventDispatcher $eventDispatcher, LoggerInterface $logger) {
51
-		$this->eventDispatcher = $eventDispatcher;
52
-		$this->logger = $logger;
53
-	}
54
-
55
-	private static function detectEventAndName($a, $b) {
56
-		if (is_object($a) && (is_string($b) || $b === null)) {
57
-			// a is the event, the other one is the optional name
58
-			return [$a, $b];
59
-		}
60
-		if (is_object($b) && (is_string($a) || $a === null)) {
61
-			// b is the event, the other one is the optional name
62
-			return [$b, $a];
63
-		}
64
-		if (is_string($a) && $b === null) {
65
-			// a is a payload-less event
66
-			return [null, $a];
67
-		}
68
-		if (is_string($b) && $a === null) {
69
-			// b is a payload-less event
70
-			return [null, $b];
71
-		}
72
-
73
-		// Anything else we can't detect
74
-		return [$a, $b];
75
-	}
76
-
77
-	/**
78
-	 * Dispatches an event to all registered listeners.
79
-	 *
80
-	 * @param string $eventName The name of the event to dispatch. The name of
81
-	 *                              the event is the name of the method that is
82
-	 *                              invoked on listeners.
83
-	 * @param Event|null $event The event to pass to the event handlers/listeners
84
-	 *                              If not supplied, an empty Event instance is created
85
-	 *
86
-	 * @return object the emitted event
87
-	 * @deprecated 20.0.0
88
-	 */
89
-	public function dispatch($eventName, $event = null): object {
90
-		[$event, $eventName] = self::detectEventAndName($event, $eventName);
91
-
92
-		// type hinting is not possible, due to usage of GenericEvent
93
-		if ($event instanceof Event && $eventName === null) {
94
-			$this->eventDispatcher->dispatchTyped($event);
95
-			return $event;
96
-		}
97
-		if ($event instanceof Event) {
98
-			$this->eventDispatcher->dispatch($eventName, $event);
99
-			return $event;
100
-		}
101
-
102
-		if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
103
-			$newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
104
-		} else {
105
-			$newEvent = $event;
106
-
107
-			// Legacy event
108
-			$this->logger->debug(
109
-				'Deprecated event type for {name}: {class}',
110
-				['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
111
-			);
112
-		}
113
-
114
-		// Event with no payload (object) need special handling
115
-		if ($newEvent === null) {
116
-			$this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName);
117
-			return new Event();
118
-		}
119
-
120
-		// Flip the argument order for Symfony to prevent a trigger_error
121
-		return $this->eventDispatcher->getSymfonyDispatcher()->dispatch($newEvent, $eventName);
122
-	}
123
-
124
-	/**
125
-	 * Adds an event listener that listens on the specified events.
126
-	 *
127
-	 * @param string $eventName The event to listen on
128
-	 * @param callable $listener The listener
129
-	 * @param int $priority The higher this value, the earlier an event
130
-	 *                            listener will be triggered in the chain (defaults to 0)
131
-	 * @deprecated 20.0.0
132
-	 */
133
-	public function addListener($eventName, $listener, $priority = 0) {
134
-		if (is_callable($listener)) {
135
-			$this->eventDispatcher->addListener($eventName, $listener, $priority);
136
-		} else {
137
-			// Legacy listener
138
-			$this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority);
139
-		}
140
-	}
141
-
142
-	/**
143
-	 * Adds an event subscriber.
144
-	 *
145
-	 * The subscriber is asked for all the events it is
146
-	 * interested in and added as a listener for these events.
147
-	 * @deprecated 20.0.0
148
-	 */
149
-	public function addSubscriber(EventSubscriberInterface $subscriber) {
150
-		$this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber);
151
-	}
152
-
153
-	/**
154
-	 * Removes an event listener from the specified events.
155
-	 *
156
-	 * @param string $eventName The event to remove a listener from
157
-	 * @param callable $listener The listener to remove
158
-	 * @deprecated 20.0.0
159
-	 */
160
-	public function removeListener($eventName, $listener) {
161
-		$this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener);
162
-	}
163
-
164
-	/**
165
-	 * @deprecated 20.0.0
166
-	 */
167
-	public function removeSubscriber(EventSubscriberInterface $subscriber) {
168
-		$this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber);
169
-	}
170
-
171
-	/**
172
-	 * Gets the listeners of a specific event or all listeners sorted by descending priority.
173
-	 *
174
-	 * @param string|null $eventName The name of the event
175
-	 *
176
-	 * @return array The event listeners for the specified event, or all event listeners by event name
177
-	 * @deprecated 20.0.0
178
-	 */
179
-	public function getListeners($eventName = null) {
180
-		return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName);
181
-	}
182
-
183
-	/**
184
-	 * Gets the listener priority for a specific event.
185
-	 *
186
-	 * Returns null if the event or the listener does not exist.
187
-	 *
188
-	 * @param string $eventName The name of the event
189
-	 * @param callable $listener The listener
190
-	 *
191
-	 * @return int|null The event listener priority
192
-	 * @deprecated 20.0.0
193
-	 */
194
-	public function getListenerPriority($eventName, $listener) {
195
-		return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener);
196
-	}
197
-
198
-	/**
199
-	 * Checks whether an event has any registered listeners.
200
-	 *
201
-	 * @param string|null $eventName The name of the event
202
-	 *
203
-	 * @return bool true if the specified event has any listeners, false otherwise
204
-	 * @deprecated 20.0.0
205
-	 */
206
-	public function hasListeners($eventName = null) {
207
-		return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName);
208
-	}
43
+    /** @var EventDispatcher */
44
+    private $eventDispatcher;
45
+    private LoggerInterface $logger;
46
+
47
+    /**
48
+     * @deprecated 20.0.0
49
+     */
50
+    public function __construct(EventDispatcher $eventDispatcher, LoggerInterface $logger) {
51
+        $this->eventDispatcher = $eventDispatcher;
52
+        $this->logger = $logger;
53
+    }
54
+
55
+    private static function detectEventAndName($a, $b) {
56
+        if (is_object($a) && (is_string($b) || $b === null)) {
57
+            // a is the event, the other one is the optional name
58
+            return [$a, $b];
59
+        }
60
+        if (is_object($b) && (is_string($a) || $a === null)) {
61
+            // b is the event, the other one is the optional name
62
+            return [$b, $a];
63
+        }
64
+        if (is_string($a) && $b === null) {
65
+            // a is a payload-less event
66
+            return [null, $a];
67
+        }
68
+        if (is_string($b) && $a === null) {
69
+            // b is a payload-less event
70
+            return [null, $b];
71
+        }
72
+
73
+        // Anything else we can't detect
74
+        return [$a, $b];
75
+    }
76
+
77
+    /**
78
+     * Dispatches an event to all registered listeners.
79
+     *
80
+     * @param string $eventName The name of the event to dispatch. The name of
81
+     *                              the event is the name of the method that is
82
+     *                              invoked on listeners.
83
+     * @param Event|null $event The event to pass to the event handlers/listeners
84
+     *                              If not supplied, an empty Event instance is created
85
+     *
86
+     * @return object the emitted event
87
+     * @deprecated 20.0.0
88
+     */
89
+    public function dispatch($eventName, $event = null): object {
90
+        [$event, $eventName] = self::detectEventAndName($event, $eventName);
91
+
92
+        // type hinting is not possible, due to usage of GenericEvent
93
+        if ($event instanceof Event && $eventName === null) {
94
+            $this->eventDispatcher->dispatchTyped($event);
95
+            return $event;
96
+        }
97
+        if ($event instanceof Event) {
98
+            $this->eventDispatcher->dispatch($eventName, $event);
99
+            return $event;
100
+        }
101
+
102
+        if ($event instanceof GenericEvent && get_class($event) === GenericEvent::class) {
103
+            $newEvent = new GenericEventWrapper($this->logger, $eventName, $event);
104
+        } else {
105
+            $newEvent = $event;
106
+
107
+            // Legacy event
108
+            $this->logger->debug(
109
+                'Deprecated event type for {name}: {class}',
110
+                ['name' => $eventName, 'class' => is_object($event) ? get_class($event) : 'null']
111
+            );
112
+        }
113
+
114
+        // Event with no payload (object) need special handling
115
+        if ($newEvent === null) {
116
+            $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName);
117
+            return new Event();
118
+        }
119
+
120
+        // Flip the argument order for Symfony to prevent a trigger_error
121
+        return $this->eventDispatcher->getSymfonyDispatcher()->dispatch($newEvent, $eventName);
122
+    }
123
+
124
+    /**
125
+     * Adds an event listener that listens on the specified events.
126
+     *
127
+     * @param string $eventName The event to listen on
128
+     * @param callable $listener The listener
129
+     * @param int $priority The higher this value, the earlier an event
130
+     *                            listener will be triggered in the chain (defaults to 0)
131
+     * @deprecated 20.0.0
132
+     */
133
+    public function addListener($eventName, $listener, $priority = 0) {
134
+        if (is_callable($listener)) {
135
+            $this->eventDispatcher->addListener($eventName, $listener, $priority);
136
+        } else {
137
+            // Legacy listener
138
+            $this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority);
139
+        }
140
+    }
141
+
142
+    /**
143
+     * Adds an event subscriber.
144
+     *
145
+     * The subscriber is asked for all the events it is
146
+     * interested in and added as a listener for these events.
147
+     * @deprecated 20.0.0
148
+     */
149
+    public function addSubscriber(EventSubscriberInterface $subscriber) {
150
+        $this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber);
151
+    }
152
+
153
+    /**
154
+     * Removes an event listener from the specified events.
155
+     *
156
+     * @param string $eventName The event to remove a listener from
157
+     * @param callable $listener The listener to remove
158
+     * @deprecated 20.0.0
159
+     */
160
+    public function removeListener($eventName, $listener) {
161
+        $this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener);
162
+    }
163
+
164
+    /**
165
+     * @deprecated 20.0.0
166
+     */
167
+    public function removeSubscriber(EventSubscriberInterface $subscriber) {
168
+        $this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber);
169
+    }
170
+
171
+    /**
172
+     * Gets the listeners of a specific event or all listeners sorted by descending priority.
173
+     *
174
+     * @param string|null $eventName The name of the event
175
+     *
176
+     * @return array The event listeners for the specified event, or all event listeners by event name
177
+     * @deprecated 20.0.0
178
+     */
179
+    public function getListeners($eventName = null) {
180
+        return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName);
181
+    }
182
+
183
+    /**
184
+     * Gets the listener priority for a specific event.
185
+     *
186
+     * Returns null if the event or the listener does not exist.
187
+     *
188
+     * @param string $eventName The name of the event
189
+     * @param callable $listener The listener
190
+     *
191
+     * @return int|null The event listener priority
192
+     * @deprecated 20.0.0
193
+     */
194
+    public function getListenerPriority($eventName, $listener) {
195
+        return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener);
196
+    }
197
+
198
+    /**
199
+     * Checks whether an event has any registered listeners.
200
+     *
201
+     * @param string|null $eventName The name of the event
202
+     *
203
+     * @return bool true if the specified event has any listeners, false otherwise
204
+     * @deprecated 20.0.0
205
+     */
206
+    public function hasListeners($eventName = null) {
207
+        return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName);
208
+    }
209 209
 }
Please login to merge, or discard this patch.