SafeBrowsingExtension::setHttpClient()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
crap 2
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