Skip to content

Commit 91dfbd0

Browse files
use nullsafe operator in Connection (#41544)
1 parent 4d770fd commit 91dfbd0

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

src/Illuminate/Database/Connection.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,7 @@ public function beforeExecuting(Closure $callback)
852852
*/
853853
public function listen(Closure $callback)
854854
{
855-
if (isset($this->events)) {
856-
$this->events->listen(Events\QueryExecuted::class, $callback);
857-
}
855+
$this->events?->listen(Events\QueryExecuted::class, $callback);
858856
}
859857

860858
/**
@@ -865,11 +863,7 @@ public function listen(Closure $callback)
865863
*/
866864
protected function fireConnectionEvent($event)
867865
{
868-
if (! isset($this->events)) {
869-
return;
870-
}
871-
872-
return $this->events->dispatch(match ($event) {
866+
return $this->events?->dispatch(match ($event) {
873867
'beganTransaction' => new TransactionBeginning($this),
874868
'committed' => new TransactionCommitted($this),
875869
'rollingBack' => new TransactionRolledBack($this),
@@ -885,9 +879,7 @@ protected function fireConnectionEvent($event)
885879
*/
886880
protected function event($event)
887881
{
888-
if (isset($this->events)) {
889-
$this->events->dispatch($event);
890-
}
882+
$this->events?->dispatch($event);
891883
}
892884

893885
/**

src/Illuminate/Redis/Connections/Connection.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ public function command($method, array $parameters = [])
132132
*/
133133
protected function event($event)
134134
{
135-
if (isset($this->events)) {
136-
$this->events->dispatch($event);
137-
}
135+
$this->events?->dispatch($event);
138136
}
139137

140138
/**
@@ -145,9 +143,7 @@ protected function event($event)
145143
*/
146144
public function listen(Closure $callback)
147145
{
148-
if (isset($this->events)) {
149-
$this->events->listen(CommandExecuted::class, $callback);
150-
}
146+
$this->events?->listen(CommandExecuted::class, $callback);
151147
}
152148

153149
/**

0 commit comments

Comments
 (0)