Passed
Pull Request — master (#1)
by Dmitriy
03:26 queued 37s
created

SentryProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 10
c 2
b 0
f 0
dl 0
loc 20
ccs 0
cts 8
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Sentry\Provider;
6
7
use Psr\Log\LoggerInterface;
8
use Sentry\ClientBuilder;
9
use Sentry\Options;
10
use Sentry\SentrySdk;
11
use Sentry\State\HubInterface;
12
use Sentry\Transport\TransportFactoryInterface;
13
use Yiisoft\Di\Container;
14
use Yiisoft\Di\Support\ServiceProvider;
15
16
final class SentryProvider extends ServiceProvider
17
{
18
    /**
19
     * @psalm-suppress InaccessibleMethod
20
     */
21
    public function register(Container $container): void
22
    {
23
        $options = $container->get(Options::class);
24
25
        $clientBuilder = new ClientBuilder($options);
26
        $clientBuilder
27
            ->setTransportFactory($container->get(TransportFactoryInterface::class))
28
            ->setLogger($container->get(LoggerInterface::class));
29
30
        $client = $clientBuilder->getClient();
31
32
        $hub = $container->get(HubInterface::class);
33
        $hub->bindClient($client);
34
35
        SentrySdk::setCurrentHub($hub);
36
    }
37
}
38