Completed
Branch master (d9d9e6)
by Thomas Mauro
05:00
created

ClientConfigFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 57
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 54 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\SentryModule\Service;
6
7
use Psr\Container\ContainerInterface;
8
use Sentry\ClientBuilder;
9
use Sentry\ClientInterface;
10
11
final class ClientConfigFactory
12
{
13
    public function __invoke(ContainerInterface $container): ClientInterface
14
    {
15
        $config = $container->get('config')['sentry'];
16
17
        $options = \array_filter(
18
            $config['options'] ?? [],
19
            static function ($value) {
20
                return null !== $value;
21
            }
22
        );
23
24
        $resolves = [
25
            'before_breadcrumbs',
26
            'before_send',
27
        ];
28
29
        $options = \array_merge(
30
            $options,
31
            \array_map(
32
                static function (string $value) use ($container): callable {
33
                    return $container->get($value);
34
                },
35
                \array_intersect_key($options, \array_flip($resolves))
36
            )
37
        );
38
39
        $builder = ClientBuilder::create($options);
40
41
        if (\is_string($config['transport'] ?? null)) {
42
            $builder->setTransport($container->get($config['transport']));
43
        }
44
45
        if (\is_string($config['http_client'] ?? null)) {
46
            $builder->setHttpClient($container->get($config['http_client']));
47
        }
48
49
        if (\is_string($config['message_factory'] ?? null)) {
50
            $builder->setMessageFactory($container->get($config['message_factory']));
51
        }
52
53
        if (\is_string($config['uri_factory'] ?? null)) {
54
            $builder->setUriFactory($container->get($config['uri_factory']));
55
        }
56
57
        if (\is_string($config['representation_serializer'] ?? null)) {
58
            $builder->setRepresentationSerializer($container->get($config['representation_serializer']));
59
        }
60
61
        if (\is_string($config['serializer'] ?? null)) {
62
            $builder->setSerializer($container->get($config['serializer']));
63
        }
64
65
        return $builder->getClient();
66
    }
67
}
68