Skip to content

Commit 7d9a206

Browse files
authored
Use nullsafe operator for event dispatcher (#52024)
1 parent 867c403 commit 7d9a206

File tree

4 files changed

+9
-17
lines changed

4 files changed

+9
-17
lines changed

src/Illuminate/Auth/Passwords/PasswordBroker.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ public function sendResetLink(#[\SensitiveParameter] array $credentials, ?Closur
8282
// the current URI having nothing set in the session to indicate errors.
8383
$user->sendPasswordResetNotification($token);
8484

85-
if ($this->events) {
86-
$this->events->dispatch(new PasswordResetLinkSent($user));
87-
}
85+
$this->events?->dispatch(new PasswordResetLinkSent($user));
8886

8987
return static::RESET_LINK_SENT;
9088
}

src/Illuminate/Auth/SessionGuard.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,7 @@ public function logout()
609609
// If we have an event dispatcher instance, we can fire off the logout event
610610
// so any further processing can be done. This allows the developer to be
611611
// listening for anytime a user signs out of this application manually.
612-
if (isset($this->events)) {
613-
$this->events->dispatch(new Logout($this->name, $user));
614-
}
612+
$this->events?->dispatch(new Logout($this->name, $user));
615613

616614
// Once we have fired the logout event we will clear the users out of memory
617615
// so they are no longer available as the user is no longer considered as
@@ -637,9 +635,7 @@ public function logoutCurrentDevice()
637635
// If we have an event dispatcher instance, we can fire off the logout event
638636
// so any further processing can be done. This allows the developer to be
639637
// listening for anytime a user signs out of this application manually.
640-
if (isset($this->events)) {
641-
$this->events->dispatch(new CurrentDeviceLogout($this->name, $user));
642-
}
638+
$this->events?->dispatch(new CurrentDeviceLogout($this->name, $user));
643639

644640
// Once we have fired the logout event we will clear the users out of memory
645641
// so they are no longer available as the user is no longer considered as

src/Illuminate/Log/Logger.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,7 @@ protected function fireLogEvent($level, $message, array $context = [])
244244
// If the event dispatcher is set, we will pass along the parameters to the
245245
// log listeners. These are useful for building profilers or other tools
246246
// that aggregate all of the log messages for a given "request" cycle.
247-
if (isset($this->dispatcher)) {
248-
$this->dispatcher->dispatch(new MessageLogged($level, $message, $context));
249-
}
247+
$this->dispatcher?->dispatch(new MessageLogged($level, $message, $context));
250248
}
251249

252250
/**

src/Illuminate/Redis/Connections/Connection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,9 @@ public function command($method, array $parameters = [])
117117

118118
$time = round((microtime(true) - $start) * 1000, 2);
119119

120-
if (isset($this->events)) {
121-
$this->event(new CommandExecuted(
122-
$method, $this->parseParametersForEvent($parameters), $time, $this
123-
));
124-
}
120+
$this->events?->dispatch(new CommandExecuted(
121+
$method, $this->parseParametersForEvent($parameters), $time, $this
122+
));
125123

126124
return $result;
127125
}
@@ -142,6 +140,8 @@ protected function parseParametersForEvent(array $parameters)
142140
*
143141
* @param mixed $event
144142
* @return void
143+
*
144+
* @deprecated since Laravel 11.x
145145
*/
146146
protected function event($event)
147147
{

0 commit comments

Comments
 (0)