From cd8c777b795cec4794e2868b694d903bc6622671 Mon Sep 17 00:00:00 2001 From: Ian Morland Date: Sun, 12 Nov 2023 16:38:25 +0000 Subject: [PATCH] fix: phpstan fixes --- src/Performance/Extension.php | 4 ++-- .../Middleware/MeasurePerformanceMiddleware.php | 7 +++++-- src/Reporters/SentryReporter.php | 8 +------- src/SentryServiceProvider.php | 6 +++--- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Performance/Extension.php b/src/Performance/Extension.php index 2032bd3..ae26068 100644 --- a/src/Performance/Extension.php +++ b/src/Performance/Extension.php @@ -48,14 +48,14 @@ public function measure($event) )); static::$measure->setDescription($event->extension->name); - } elseif (static::$measure) { + } elseif (static::$measure !== null) { static::$measure->finish(); } } public function __destruct() { - if (static::$parent) { + if (static::$parent !== null) { static::$parent->finish(); } } diff --git a/src/Performance/Middleware/MeasurePerformanceMiddleware.php b/src/Performance/Middleware/MeasurePerformanceMiddleware.php index dc2ef3f..89683a2 100644 --- a/src/Performance/Middleware/MeasurePerformanceMiddleware.php +++ b/src/Performance/Middleware/MeasurePerformanceMiddleware.php @@ -17,14 +17,17 @@ use Psr\Http\Server\RequestHandlerInterface; use Sentry\Tracing\Span; use Sentry\Tracing\SpanContext; -use Sentry\Tracing\Transaction; class MeasurePerformanceMiddleware implements Middleware { /** - * @var Transaction + * @var Span */ protected $transaction; + + /** + * @var string + */ protected $frontend; public function __construct(string $frontend, Span $transaction) diff --git a/src/Reporters/SentryReporter.php b/src/Reporters/SentryReporter.php index a63f440..d83a074 100644 --- a/src/Reporters/SentryReporter.php +++ b/src/Reporters/SentryReporter.php @@ -41,18 +41,12 @@ public function report(Throwable $error) /** @var HubInterface $hub */ $hub = $this->container->make('sentry'); - if ($hub === null) { - $this->logger->warning('[fof/sentry] sentry dsn not set'); - - return; - } - if ($this->container->bound('sentry.request')) { $hub->configureScope(function (Scope $scope) { $request = $this->container->make('sentry.request'); $user = RequestUtil::getActor($request); - if ($user && $user->id !== 0) { + if (!$user->isGuest() && $user->id !== 0) { $data = $user->only('id', 'username'); // Only send email if enabled in settings diff --git a/src/SentryServiceProvider.php b/src/SentryServiceProvider.php index 38872c3..485ec85 100644 --- a/src/SentryServiceProvider.php +++ b/src/SentryServiceProvider.php @@ -49,7 +49,7 @@ public function register() $this->container->singleton(HubInterface::class, function ($container) { /** @var SettingsRepositoryInterface $settings */ $settings = $container->make(SettingsRepositoryInterface::class); - /** @var UrlGenerator $urlGenerator */ + /** @var UrlGenerator $url */ $url = $container->make(UrlGenerator::class); $dsn = $settings->get('fof-sentry.dsn_backend'); $environment = empty($settings->get('fof-sentry.environment')) ? str_replace(['https://', 'http://'], '', $url->to('forum')->base()) : $settings->get('fof-sentry.environment'); @@ -94,8 +94,8 @@ public function register() $hub = $this->container->make(HubInterface::class); $hub->configureScope(function (Scope $scope) use ($config) { - $scope->setTag('offline', (int) Arr::get($config, 'offline', false)); - $scope->setTag('debug', (int) Arr::get($config, 'debug', true)); + $scope->setTag('offline', Arr::get($config, 'offline', false)); + $scope->setTag('debug', Arr::get($config, 'debug', true)); $scope->setTag('flarum', Application::VERSION); if ($this->container->bound('sentry.stack')) {