Completed
Push — master ( 0a7e57...033978 )
by Thomas Mauro
02:31
created

ClientFactory::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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
use Zend\ServiceManager\ServiceLocatorInterface;
9
10
/**
11
 * Class ClientFactory.
12
 */
13
class ClientFactory extends AbstractFactory
14
{
15
    /**
16
     * @param ContainerInterface $container
17
     * @param string $requestedName
18
     * @param array|null $options
19
     *
20
     * @return Client
21
     * @throws \RuntimeException
22
     *
23
     * @throws \Interop\Container\Exception\NotFoundException
24
     * @throws \Interop\Container\Exception\ContainerException
25
     */
26 2
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
27
    {
28
        /** @var ClientOptions $options */
29 2
        $options = $this->getOptions($container, 'client');
30
31 2
        $ravenOptions = $options->getOptions();
32
33 2
        if (!array_key_exists('processors', $ravenOptions)) {
34 2
            $ravenOptions['processors'] = [SanitizeDataProcessor::class];
35 2
        }
36
37 2
        $ravenClient = new \Raven_Client($options->getDsn(), $ravenOptions);
38
39 2
        $client = new Client($ravenClient, $options);
40
41 2
        $errorHandlerListener = $container->get($options->getErrorHandlerListener());
42 2
        if ($errorHandlerListener instanceof ClientAwareInterface) {
43 1
            $errorHandlerListener->setClient($client);
44 1
        }
45 2
        $client->setErrorHandlerListener($errorHandlerListener);
46
47 2
        return $client;
48
    }
49
50
    /**
51
     * @param ServiceLocatorInterface $serviceLocator
52
     * @return Client
53
     */
54 1
    public function createService(ServiceLocatorInterface $serviceLocator)
55
    {
56 1
        return $this($serviceLocator, Client::class);
57 1
    }
58
59
    /**
60
     * Get the class name of the options associated with this factory.
61
     *
62
     *
63
     * @return string
64
     */
65 2
    public function getOptionsClass()
66
    {
67 2
        return ClientOptions::class;
68
    }
69
}
70