Completed
Push — master ( 89c9f0...9aceec )
by Thomas Mauro
06:33
created

ClientFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
3
namespace Facile\SentryModule\Service;
4
5
use Facile\SentryModule\Options\ClientOptions;
6
use Interop\Container\ContainerInterface;
7
8
class ClientFactory extends AbstractFactory
9
{
10
    /**
11
     * @param ContainerInterface $container
12
     * @return Client
13
     * @throws \Interop\Container\Exception\NotFoundException
14
     * @throws \Interop\Container\Exception\ContainerException
15
     */
16
    public function __invoke(ContainerInterface $container)
17
    {
18
        /** @var array $optionsArray */
19
        $optionsArray = $container->get('config')['facile']['sentry']['client'][$this->name];
20
        
21
        $options = new ClientOptions($optionsArray);
22
23
        $ravenClient = new \Raven_Client($options->getDsn(), $options->getOptions());
24
25
        $client = new Client($ravenClient, $options);
26
27
        $errorHandlerListener = $container->get($options->getErrorHandlerListener());
28
        if ($errorHandlerListener instanceof ClientAwareInterface) {
29
            $errorHandlerListener->setClient($client);
30
        }
31
        $client->setErrorHandlerListener($errorHandlerListener);
32
        
33
        return $client;
34
    }
35
}
36