Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
created

KunstmaanDashboardExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\DashboardBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
/**
12
 * This is the class that loads and manages your bundle configuration
13
 *
14
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
15
 */
16
class KunstmaanDashboardExtension extends Extension implements PrependExtensionInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 13 View Code Duplication
    public function load(array $configs, ContainerBuilder $container)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23 13
        $configuration = new Configuration();
24 13
        $config = $this->processConfiguration($configuration, $configs);
25
26 13
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
27 13
        $loader->load('services.yml');
28 13
        $loader->load('commands.yml');
29
30 13
        $this->loadGoogleAnalyticsParameters($container, $config);
31 13
    }
32
33 13
    public function prepend(ContainerBuilder $container)
34
    {
35 13
        $container->prependExtensionConfig('framework', ['esi' => ['enabled' => true]]);
36 13
    }
37
38 13
    private function loadGoogleAnalyticsParameters(ContainerBuilder $container, array $config)
39
    {
40 13
        $this->addApplicationNameParameter($container, $config);
41 13
        $this->addClientIdParameter($container, $config);
42 13
        $this->addClientSecretParameter($container, $config);
43 13
        $this->addDeveloperKeyParameter($container, $config);
44 13
    }
45
46 13 View Code Duplication
    private function addClientIdParameter(ContainerBuilder $container, array $config)
47
    {
48 13
        $clientId = $container->hasParameter('google.api.client_id') ? $container->getParameter('google.api.client_id') : '';
49 13
        if (null === $config['google_analytics']['api']['client_id'] && $clientId !== '') {
50 1
            @trigger_error('Not providing a value for the "kunstmaan_dashboard.google_analytics.api.client_id" config while setting the "google.api.client_id" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "google.api.client_id" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED);
51
        }
52
53 13
        if (null !== $config['google_analytics']['api']['client_id']) {
54 1
            $clientId = $config['google_analytics']['api']['client_id'];
55
        }
56
57 13
        $container->setParameter('kunstmaan_dashboard.google_analytics.api.client_id', $clientId);
58 13
    }
59
60 13 View Code Duplication
    private function addClientSecretParameter(ContainerBuilder $container, array $config)
61
    {
62 13
        $clientSecret = $container->hasParameter('google.api.client_secret') ? $container->getParameter('google.api.client_secret') : '';
63 13
        if (null === $config['google_analytics']['api']['client_secret'] && $clientSecret !== '') {
64 1
            @trigger_error('Not providing a value for the "kunstmaan_dashboard.google_analytics.api.client_secret" config while setting the "google.api.client_secret" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "google.api.client_secret" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED);
65
        }
66
67 13
        if (null !== $config['google_analytics']['api']['client_secret']) {
68 1
            $clientSecret = $config['google_analytics']['api']['client_secret'];
69
        }
70
71 13
        $container->setParameter('kunstmaan_dashboard.google_analytics.api.client_secret', $clientSecret);
72 13
    }
73
74 13 View Code Duplication
    private function addDeveloperKeyParameter(ContainerBuilder $container, array $config)
75
    {
76 13
        $devKey = $container->hasParameter('google.api.dev_key') ? $container->getParameter('google.api.dev_key') : '';
77 13
        if (null === $config['google_analytics']['api']['dev_key'] && $devKey !== '') {
78 1
            @trigger_error('Not providing a value for the "kunstmaan_dashboard.google_analytics.api.dev_key" config while setting the "google.api.dev_key" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "google.api.dev_key" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED);
79
        }
80
81 13
        if (null !== $config['google_analytics']['api']['dev_key']) {
82 1
            $devKey = $config['google_analytics']['api']['dev_key'];
83
        }
84
85 13
        $container->setParameter('kunstmaan_dashboard.google_analytics.api.dev_key', $devKey);
86 13
    }
87
88 13 View Code Duplication
    private function addApplicationNameParameter(ContainerBuilder $container, array $config)
89
    {
90 13
        $appName = $container->hasParameter('google.api.app_name') ? $container->getParameter('google.api.app_name') : 'Kuma Analytics Dashboard';
91 13
        if (null === $config['google_analytics']['api']['app_name'] && $appName !== '' && $appName !== 'Kuma Analytics Dashboard') {
92 1
            @trigger_error('Not providing a value for the "kunstmaan_dashboard.google_analytics.api.app_name" config while setting the "google.api.app_name" parameter is deprecated since KunstmaanDashboardBundle 5.2, this config value will replace the "google.api.app_name" parameter in KunstmaanDashboardBundle 6.0.', E_USER_DEPRECATED);
93
        }
94
95 13
        if (null !== $config['google_analytics']['api']['app_name']) {
96 1
            $appName = $config['google_analytics']['api']['app_name'];
97
        }
98
99 13
        $container->setParameter('kunstmaan_dashboard.google_analytics.api.app_name', $appName);
100 13
    }
101
}
102