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

ExceptionContextIntegration::setupOnce()   A

Complexity

Conditions 6
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 11
nc 1
nop 0
dl 0
loc 17
ccs 12
cts 12
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
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