Completed
Pull Request — master (#5)
by Thomas Mauro
04:44 queued 01:37
created

Module   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 96.3%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 6
dl 0
loc 60
ccs 26
cts 27
cp 0.963
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 4 1
B onBootstrap() 0 36 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
        /** @var ConfigurationOptions $configurationOptions */
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(
69 1
                'Raven.config(\'%s\', %s).install();',
70 1
                $configurationOptions->getRavenJavascriptDsn(),
71 1
                json_encode($configurationOptions->getRavenJavascriptOptions())
72 1
            )
73 1
        );
74
    }
75
}
76