DomainParserExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 79.17%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 56
ccs 19
cts 24
cp 0.7917
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 13 1
A setCacheDir() 0 10 2
A setHttpAdapter() 0 13 2
1
<?php
2
3
namespace EmanueleMinotto\DomainParserBundle\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 DomainParserExtension extends Extension
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 39
    public function load(array $configs, ContainerBuilder $container)
20
    {
21 39
        $config = $this->processConfiguration(new Configuration(), $configs);
22
23 39
        $loader = new Loader\XmlFileLoader(
24 39
            $container,
25 39
            new FileLocator(__DIR__.'/../Resources/config')
26 39
        );
27 39
        $loader->load('services.xml');
28
29 39
        $this->setCacheDir($config['cache_dir'], $container);
30 39
        $this->setHttpAdapter($config['http_adapter'], $container);
31 39
    }
32
33
    /**
34
     * Set cache directory.
35
     *
36
     * @param string           $cacheDir
37
     * @param ContainerBuilder $container
38
     */
39 39
    private function setCacheDir($cacheDir, ContainerBuilder $container)
40
    {
41 39
        if (!$cacheDir) {
42 36
            return;
43
        }
44
45
        $container
46 3
            ->getDefinition('pdp.public_suffix_list_manager')
47 3
            ->replaceArgument(0, $cacheDir);
48 3
    }
49
50
    /**
51
     * Set HTTP adapter.
52
     *
53
     * @param string           $httpAdapter
54
     * @param ContainerBuilder $container
55
     */
56 39
    private function setHttpAdapter($httpAdapter, ContainerBuilder $container)
57
    {
58 39
        if (!$httpAdapter) {
59 39
            return;
60
        }
61
62
        $container
63
            ->getDefinition('pdp.public_suffix_list_manager')
64
            ->addMethodCall('setHttpAdapter', [new Reference($httpAdapter)]);
65
        $container
66
            ->getDefinition('domain_parser_bundle.cached_domains_list_warmer')
67
            ->replaceArgument(0, new Reference($httpAdapter));
68
    }
69
}
70