Passed
Pull Request — master (#19)
by
unknown
02:55
created

ExceptionContextIntegration   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A setupOnce() 0 17 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Sentry\Integration;
6
7
use Sentry\Event;
8
use Sentry\EventHint;
9
use Sentry\Integration\IntegrationInterface;
10
use Sentry\SentrySdk;
11
use Sentry\State\Scope;
12
13
class ExceptionContextIntegration implements IntegrationInterface
14
{
15 5
    public function setupOnce(): void
16
    {
17 1
        Scope::addGlobalEventProcessor(
18 1
            static function (Event $event, ?EventHint $hint = null): Event {
19 5
                $self = SentrySdk::getCurrentHub()->getIntegration(self::class);
20
21 5
                if (!$self instanceof self
22 2
                    || $hint === null
23 2
                    || $hint->exception === null
24 1
                    || !method_exists($hint->exception, 'context')
25 5
                    || !is_array($hint->exception->context())
26
                ) {
27 4
                    return $event;
28
                }
29 1
                $event->setExtra(['exception_context' => $hint->exception->context()]);
30
31 1
                return $event;
32
            }
33
        );
34
    }
35
}
36