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

InnmindRestClientExtension::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

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