SafeBrowsingExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 27.03 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 7
dl 20
loc 74
ccs 27
cts 27
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 14 1
A setCache() 10 10 2
A setConfigs() 0 6 1
A setHttpClient() 10 10 2

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 EmanueleMinotto\SafeBrowsingBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Loader;
8
use Symfony\Component\DependencyInjection\Reference;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
/**
12
 * {@inheritdoc}
13
 */
14
class SafeBrowsingExtension extends Extension
15
{
16
    /**
17
     * Main service ID.
18
     *
19
     * @var string
20
     */
21
    const SERVICE_ID = 'safe_browsing_bundle.validator.constraints.safe_validator';
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 15
    public function load(array $configs, ContainerBuilder $container)
27
    {
28 15
        $config = $this->processConfiguration(new Configuration(), $configs);
29
30 15
        $loader = new Loader\XmlFileLoader(
31 15
            $container,
32 15
            new FileLocator(__DIR__.'/../Resources/config')
33 15
        );
34 15
        $loader->load('services.xml');
35
36 15
        $this->setCache($config['cache'], $container);
37 15
        $this->setConfigs($config['configs'], $container);
38 15
        $this->setHttpClient($config['http_client'], $container);
39 15
    }
40
41
    /**
42
     * Set cache directory.
43
     *
44
     * @param string           $cache
45
     * @param ContainerBuilder $container
46
     */
47 15 View Code Duplication
    private function setCache($cache, 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...
48
    {
49 15
        if (!$cache) {
50 12
            return;
51
        }
52
53
        $container
54 3
            ->getDefinition(self::SERVICE_ID)
55 3
            ->addMethodCall('setCache', [new Reference($cache)]);
56 3
    }
57
58
    /**
59
     * Initialize service configuration.
60
     *
61
     * @param array            $configs
62
     * @param ContainerBuilder $container
63
     */
64 15
    private function setConfigs(array $configs, ContainerBuilder $container)
65
    {
66
        $container
67 15
            ->getDefinition(self::SERVICE_ID)
68 15
            ->replaceArgument(0, $configs);
69 15
    }
70
71
    /**
72
     * Set HTTP client.
73
     *
74
     * @param string           $httpClient
75
     * @param ContainerBuilder $container
76
     */
77 15 View Code Duplication
    private function setHttpClient($httpClient, 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...
78
    {
79 15
        if (!$httpClient) {
80 12
            return;
81
        }
82
83
        $container
84 3
            ->getDefinition(self::SERVICE_ID)
85 3
            ->addMethodCall('setHttpClient', [new Reference($httpClient)]);
86 3
    }
87
}
88