From d1fa5d1edeb049585175577c5dea13da66d56cdf Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 29 Mar 2022 22:16:19 +0200 Subject: [PATCH] Make eventName required if no $event is passed in --- src/Composer/EventDispatcher/EventDispatcher.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Composer/EventDispatcher/EventDispatcher.php b/src/Composer/EventDispatcher/EventDispatcher.php index b57e577d8..6152c0bab 100644 --- a/src/Composer/EventDispatcher/EventDispatcher.php +++ b/src/Composer/EventDispatcher/EventDispatcher.php @@ -91,14 +91,17 @@ class EventDispatcher /** * Dispatch an event * - * @param string|null $eventName An event name if no $event is provided - * @param Event $event + * @param string|null $eventName The event name, required if no $event is provided + * @param Event $event An event instance, required if no $eventName is provided * @return int return code of the executed script if any, for php scripts a false return * value is changed to 1, anything else to 0 */ public function dispatch(?string $eventName, Event $event = null): int { if (null === $event) { + if (null === $eventName) { + throw new \InvalidArgumentException('If no $event is passed in to '.__METHOD__.' you have to pass in an $eventName, got null.'); + } $event = new Event($eventName); }