Completed
Push — develop ( d3bb0f...88b170 )
by Baptiste
05:23
created

InnmindRestClientExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 49
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 16 1
A registerTypes() 0 15 2
A registerContentTypeFormats() 0 10 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ClientBundle\DependencyInjection;
5
6
use Symfony\Component\{
7
    HttpKernel\DependencyInjection\Extension,
8
    DependencyInjection\ContainerBuilder,
9
    DependencyInjection\Loader,
10
    Config\FileLocator
11
};
12
13
final class InnmindRestClientExtension extends Extension
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 1
    public function load(array $configs, ContainerBuilder $container)
19
    {
20 1
        $loader = new Loader\YamlFileLoader(
21
            $container,
22 1
            new FileLocator(__DIR__.'/../Resources/config')
23
        );
24 1
        $loader->load('services.yml');
25 1
        $config = $this->processConfiguration(
26 1
            new Configuration,
27
            $configs
28
        );
29
30
        $this
31 1
            ->registerTypes($config['types'], $container)
32 1
            ->registerContentTypeFormats($config['content_type'], $container);
33 1
    }
34
35 1
    private function registerTypes(array $types, ContainerBuilder $container): self
36
    {
37 1
        $definition = $container->getDefinition(
38 1
            'innmind_rest_client.definition.types'
39
        );
40
41 1
        foreach ($types as $type) {
42 1
            $definition->addMethodCall(
43 1
                'register',
44 1
                [$type]
45
            );
46
        }
47
48 1
        return $this;
49
    }
50
51 1
    private function registerContentTypeFormats(
52
        array $formats,
53
        ContainerBuilder $container
54
    ): self {
55
        $container
56 1
            ->getDefinition('innmind_rest_client.formats.content_type')
57 1
            ->replaceArgument(0, $formats);
58
59 1
        return $this;
60
    }
61
}
62