Completed
Push — master ( 56fc22...f11276 )
by Thomas Mauro
06:14 queued 04:10
created

ClientFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 3
c 3
b 1
f 1
lcom 0
cbo 6
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 25 3
1
<?php
2
3
namespace Facile\SentryModule\Service;
4
5
use Facile\SentryModule\Options\ClientOptions;
6
use Facile\SentryModule\Processor\SanitizeDataProcessor;
7
use Interop\Container\ContainerInterface;
8
9
/**
10
 * Class ClientFactory.
11
 */
12
class ClientFactory extends AbstractFactory
13
{
14
    /**
15
     * @param ContainerInterface $container
16
     *
17
     * @return Client
18
     *
19
     * @throws \Interop\Container\Exception\NotFoundException
20
     * @throws \Interop\Container\Exception\ContainerException
21
     */
22
    public function __invoke(ContainerInterface $container)
23
    {
24
        /** @var array $optionsArray */
25
        $optionsArray = $container->get('config')['facile']['sentry']['client'][$this->name];
26
27
        $options = new ClientOptions($optionsArray);
28
29
        $ravenOptions = $options->getOptions();
30
31
        if (!array_key_exists('processors', $ravenOptions)) {
32
            $ravenOptions['processors'] = [SanitizeDataProcessor::class];
33
        }
34
35
        $ravenClient = new \Raven_Client($options->getDsn(), $ravenOptions);
36
37
        $client = new Client($ravenClient, $options);
38
39
        $errorHandlerListener = $container->get($options->getErrorHandlerListener());
40
        if ($errorHandlerListener instanceof ClientAwareInterface) {
41
            $errorHandlerListener->setClient($client);
42
        }
43
        $client->setErrorHandlerListener($errorHandlerListener);
44
45
        return $client;
46
    }
47
}
48