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

addApplicationNameParameter()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 6

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 8
cts 8
cp 1
rs 9.2222
c 0
b 0
f 0
cc 6
nc 8
nop 2
crap 6
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
Duplication introduced by
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)
0 ignored issues
show
Duplication introduced by
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...
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);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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)
0 ignored issues
show
Duplication introduced by
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...
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);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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)
0 ignored issues
show
Duplication introduced by
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...
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);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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)
0 ignored issues
show
Duplication introduced by
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...
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);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
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