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

ClientFactory::__invoke()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 25
rs 8.8571
cc 3
eloc 13
nc 4
nop 1
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