From 726b5d68d7e26ed325fc635edc239074f7ea6a85 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Wed, 12 Oct 2022 10:20:40 +0200 Subject: [PATCH] Tiny refactoring --- src/Sentry/Laravel/EventHandler.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Sentry/Laravel/EventHandler.php b/src/Sentry/Laravel/EventHandler.php index 39fccea7..5ad15db6 100644 --- a/src/Sentry/Laravel/EventHandler.php +++ b/src/Sentry/Laravel/EventHandler.php @@ -28,7 +28,6 @@ use Sentry\SentrySdk; use Sentry\State\Scope; use Symfony\Component\Console\Input\ArgvInput; -use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; class EventHandler @@ -572,7 +571,7 @@ protected function commandStartingHandler(CommandStarting $event) 'artisan.command', 'Starting Artisan command: ' . $event->command, [ - 'input' => $this->extractCommandInput($event->input), + 'input' => $this->extractConsoleCommandInput($event->input), ] )); } @@ -593,21 +592,27 @@ protected function commandFinishedHandler(CommandFinished $event) 'Finished Artisan command: ' . $event->command, [ 'exit' => $event->exitCode, - 'input' => $this->extractCommandInput($event->input), + 'input' => $this->extractConsoleCommandInput($event->input), ] )); } - Integration::configureScope(static function (Scope $scope): void { - $scope->setTag('command', ''); - }); - // Flush any and all events that were possibly generated by the command Integration::flushEvents(); + + Integration::configureScope(static function (Scope $scope): void { + $scope->removeTag('command'); + }); } - /** @return string|null */ - private function extractCommandInput(InputInterface $input) + /** + * Extract the command input arguments if possible. + * + * @param \Symfony\Component\Console\Input\InputInterface|null $input + * + * @return string|null + */ + private function extractConsoleCommandInput(?InputInterface $input): ?string { if ($input instanceof ArgvInput) { return (string)$input;