Completed
Push — master ( cf475b...28c9f0 )
by Thomas Mauro
03:13
created

Module   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 56
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 4 1
B onBootstrap() 0 32 3
1
<?php
2
3
namespace Facile\SentryModule;
4
5
use Facile\SentryModule\Options\ConfigurationOptions;
6
use Facile\SentryModule\Service\Client;
7
use Facile\SentryModule\Service\ErrorHandlerRegister;
8
use Zend\EventManager\EventInterface;
9
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
10
use Zend\ModuleManager\Feature\ConfigProviderInterface;
11
use Zend\Mvc\MvcEvent;
12
13
/**
14
 * Class Module.
15
 */
16
class Module implements ConfigProviderInterface, BootstrapListenerInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 1
    public function getConfig()
22
    {
23 1
        return include __DIR__.'/../config/module.config.php';
24
    }
25
26
    /**
27
     * Listen to the bootstrap event.
28
     *
29
     * @param EventInterface $e
30
     *
31
     * @return array
32
     *
33
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
34
     * @throws \Zend\ServiceManager\Exception\InvalidServiceException
35
     * @throws \RuntimeException
36
     * @throws \Interop\Container\Exception\NotFoundException
37
     * @throws \Interop\Container\Exception\ContainerException
38
     */
39 2
    public function onBootstrap(EventInterface $e)
40
    {
41
        /* @var MvcEvent $e */
42 2
        $application = $e->getApplication();
43 2
        $container = $application->getServiceManager();
44 2
        $moduleConfig = $container->get('config')['facile']['sentry'];
45 2
        $clients = array_keys($moduleConfig['client']);
46
47 2
        $errorHandlerRegister = $container->get(ErrorHandlerRegister::class);
48
49 2
        foreach ($clients as $serviceKey) {
50 2
            $serviceName = sprintf('facile.sentry.client.%s', $serviceKey);
51
52
            /* @var Client $client */
53 2
            $client = $container->get($serviceName);
54 2
            $errorHandlerRegister->registerHandlers($client, $application->getEventManager());
55 2
        }
56
57 2
        $configurationOptions = $container->get(ConfigurationOptions::class);
58 2
        if (!$configurationOptions->isInjectRavenJavascript()) {
59 1
            return;
60
        }
61
62
        /** @var \Zend\View\HelperPluginManager $viewHelperManager */
63 1
        $viewHelperManager = $container->get('ViewHelperManager');
64
        /** @var \Zend\View\Helper\HeadScript $headScriptHelper */
65 1
        $headScriptHelper = $viewHelperManager->get('HeadScript');
66 1
        $headScriptHelper->appendFile($configurationOptions->getRavenJavascriptUri());
67 1
        $headScriptHelper->appendScript(
68 1
            sprintf('Raven.config(\'%s\').install();', $configurationOptions->getRavenJavascriptDsn())
69 1
        );
70
    }
71
}
72