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

KunstmaanDashboardExtension   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 86
Duplicated Lines 73.26 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 11 11 1
A prepend() 0 4 1
A loadGoogleAnalyticsParameters() 0 7 1
A addClientIdParameter() 13 13 5
A addClientSecretParameter() 13 13 5
A addDeveloperKeyParameter() 13 13 5
A addApplicationNameParameter() 13 13 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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