Completed
Branch master (d9d9e6)
by Thomas Mauro
05:00
created

Module   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 45
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 9 1
A onBootstrap() 0 32 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\SentryModule;
6
7
use Sentry\State\HubInterface;
8
use Zend\Mvc\MvcEvent;
9
use Zend\View\Helper\HeadScript;
10
use Zend\View\HelperPluginManager;
11
12
final class Module
13
{
14 1
    public function getConfig(): array
15
    {
16 1
        $provider = new ConfigProvider();
17 1
        $config = $provider();
18 1
        $config['service_manager'] = $provider->getDependencies();
19 1
        unset($config['dependencies']);
20
21 1
        return $config;
22
    }
23
24 2
    public function onBootstrap(MvcEvent $e): void
25
    {
26 2
        $application = $e->getApplication();
27 2
        $container = $application->getServiceManager();
28
29
        // Get the Hub to initialize it
30 2
        $container->get(HubInterface::class);
31
32
        /** @var array $appConfig */
33 2
        $appConfig = $container->get('config');
34 2
        $config = $appConfig['sentry']['javascript'] ?? [];
35 2
        $options = $config['options'] ?? [];
36
37 2
        if (! ($config['inject_script'] ?? false)) {
38 1
            return;
39
        }
40
41
        /** @var HelperPluginManager $viewHelperManager */
42 1
        $viewHelperManager = $container->get('ViewHelperManager');
43
        /** @var HeadScript $headScriptHelper */
44 1
        $headScriptHelper = $viewHelperManager->get('HeadScript');
45 1
        if ($config['script']['src'] ?? null) {
46 1
            $headScriptHelper->appendFile($config['script']['src'], 'text/javascript', $config['script']);
47
        }
48
49 1
        $headScriptHelper->appendScript(
50 1
            \sprintf(
51 1
                'Sentry.init(%s);',
52 1
                \json_encode($options)
53
            )
54
        );
55 1
    }
56
}
57