Skip to content

Commit d921cc5

Browse files
committed
Remove null checks around EventDispatcher
Originally the EventDispatcher was added with the intent that it could be nullable, however a disconnect in how it was coded in the ExceptionListener and how it was being injected left the code in a sort of paradox with itself: we were always requiring it, but we were null-checking it in the code as if it were possible to leave the dispatcher null. Ultimately, after a few other changes and suggestions from other participants in the code review it made the most sense just to require the EventDispatcher and, within the code, make the assumption that it would always be there rather than checking to see if there was a null value.
1 parent bc1648f commit d921cc5

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/Sentry/SentryBundle/EventListener/ExceptionListener.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(
5050
AuthorizationCheckerInterface $authorizationChecker = null,
5151
\Raven_Client $client = null,
5252
array $skipCapture,
53-
EventDispatcherInterface $dispatcher = null
53+
EventDispatcherInterface $dispatcher
5454
) {
5555
if (!$client) {
5656
$client = new SentrySymfonyClient();
@@ -109,9 +109,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)
109109
return;
110110
}
111111

112-
if (null !== $this->dispatcher) {
113-
$this->dispatcher->dispatch(SentrySymfonyEvents::PRE_CAPTURE, $event);
114-
}
112+
$this->dispatcher->dispatch(SentrySymfonyEvents::PRE_CAPTURE, $event);
115113
$this->client->captureException($exception);
116114
}
117115

@@ -134,9 +132,7 @@ public function onConsoleException(ConsoleExceptionEvent $event)
134132
),
135133
);
136134

137-
if (null !== $this->dispatcher) {
138-
$this->dispatcher->dispatch(SentrySymfonyEvents::PRE_CAPTURE, $event);
139-
}
135+
$this->dispatcher->dispatch(SentrySymfonyEvents::PRE_CAPTURE, $event);
140136
$this->client->captureException($exception, $data);
141137
}
142138

0 commit comments

Comments
 (0)