Completed
Push — master ( 96ff99...a0e1ef )
by Sergei
03:19
created

ConfigMergersProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 56
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getItems() 0 20 1
1
<?php
2
3
namespace Modera\BackendGoogleAnalyticsBundle\Contributions;
4
5
use Modera\BackendGoogleAnalyticsBundle\ModeraBackendGoogleAnalyticsBundle;
6
use Modera\ConfigBundle\Config\ConfigurationEntriesManagerInterface;
7
use Modera\MjrIntegrationBundle\Config\CallbackConfigMerger;
8
use Modera\SecurityBundle\Entity\User;
9
use Sli\ExpanderBundle\Ext\ContributorInterface;
10
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
11
12
/**
13
 * @author    Sergei Lissovski <[email protected]>
14
 * @copyright 2016 Modera Foundation
15
 */
16
class ConfigMergersProvider implements ContributorInterface
17
{
18
    /**
19
     * @var TokenStorageInterface
20
     */
21
    private $tokenStorage;
22
23
    /**
24
     * @var string
25
     */
26
    private $env;
27
28
    /**
29
     * @var ConfigurationEntriesManagerInterface
30
     */
31
    private $configEntriesManager;
32
33
    /**
34
     * @param TokenStorageInterface                $tokenStorage
35
     * @param ConfigurationEntriesManagerInterface $configEntriesManager
36
     * @param string                               $env
37
     */
38
    public function __construct(
39
        TokenStorageInterface $tokenStorage,
40
        ConfigurationEntriesManagerInterface $configEntriesManager,
41
        $env
42
    ) {
43
        $this->tokenStorage = $tokenStorage;
44
        $this->configEntriesManager = $configEntriesManager;
45
        $this->env = $env;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getItems()
52
    {
53
        /* @var User $user */
54
        $user = $this->tokenStorage->getToken()->getUser();
55
56
        $trackingCode = $this->configEntriesManager->findOneByNameOrDie(ModeraBackendGoogleAnalyticsBundle::TRACKING_CODE_CONFIG_KEY);
57
58
        return [
59
            new CallbackConfigMerger(function (array $currentConfig) use ($trackingCode, $user) {
60
                $currentConfig['modera_backend_google_analytics'] = array(
61
                    'user_id' => $user->getId(),
62
                    'tracking_code' => $trackingCode->getValue(),
63
                    'is_debug' => 'prod' != $this->env,
64
                    'prefix' => '/backend',
65
                );
66
67
                return $currentConfig;
68
            }),
69
        ];
70
    }
71
}
72