Completed
Push — master ( a73fad...f8ec74 )
by Baptiste
02:31
created

InnmindRestServerExtension   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 6
dl 0
loc 108
ccs 44
cts 44
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registerTypes() 0 15 2
B load() 0 26 1
A registerAcceptFormats() 0 10 1
A registerContentTypeFormats() 0 10 1
A configureRangeExtractor() 0 11 1
A configureSpecificationBuilder() 0 11 1
A configureHeaderBuilders() 0 13 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\DependencyInjection;
5
6
use Symfony\Component\{
7
    HttpKernel\DependencyInjection\Extension,
8
    DependencyInjection\ContainerBuilder,
9
    DependencyInjection\Loader,
10
    Config\FileLocator
11
};
12
13
final class InnmindRestServerExtension extends Extension
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 30
    public function load(array $configs, ContainerBuilder $container)
19
    {
20 30
        $loader = new Loader\YamlFileLoader(
21
            $container,
22 30
            new FileLocator(__DIR__.'/../Resources/config')
23
        );
24 30
        $loader->load('services.yml');
25 30
        $config = $this->processConfiguration(
26 30
            new Configuration,
27
            $configs
28
        );
29
30
        $this
31 30
            ->registerTypes($config['types'], $container)
32 30
            ->registerAcceptFormats($config['accept'], $container)
33 30
            ->registerContentTypeFormats($config['content_type'], $container)
34 30
            ->configureRangeExtractor($config['range_extractor'], $container)
35 30
            ->configureSpecificationBuilder(
36 30
                $config['specification_builder'],
37
                $container
38
            )
39 30
            ->configureHeaderBuilders(
40 30
                $config['response']['header_builders'],
41
                $container
42
            );
43 30
    }
44
45 30
    private function registerTypes(array $types, ContainerBuilder $container): self
46
    {
47 30
        $definition = $container->getDefinition(
48 30
            'innmind_rest_server.definition.types'
49
        );
50
51 30
        foreach ($types as $type) {
52 4
            $definition->addMethodCall(
53 4
                'register',
54 4
                [$type]
55
            );
56
        }
57
58 30
        return $this;
59
    }
60
61 30
    private function registerAcceptFormats(
62
        array $formats,
63
        ContainerBuilder $container
64
    ): self {
65
        $container
66 30
            ->getDefinition('innmind_rest_server.formats.accept')
67 30
            ->replaceArgument(0, $formats);
68
69 30
        return $this;
70
    }
71
72 30
    private function registerContentTypeFormats(
73
        array $formats,
74
        ContainerBuilder $container
75
    ): self {
76
        $container
77 30
            ->getDefinition('innmind_rest_server.formats.content_type')
78 30
            ->replaceArgument(0, $formats);
79
80 30
        return $this;
81
    }
82
83 30
    private function configureRangeExtractor(
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
84
        string $service,
85
        ContainerBuilder $container
86
    ): self {
87 30
        $container->setAlias(
88 30
            'innmind_rest_server.range_extractor',
89
            $service
90
        );
91
92 30
        return $this;
93
    }
94
95 30
    private function configureSpecificationBuilder(
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
96
        string $service,
97
        ContainerBuilder $container
98
    ): self {
99 30
        $container->setAlias(
100 30
            'innmind_rest_server.specification_builder',
101
            $service
102
        );
103
104 30
        return $this;
105
    }
106
107 30
    private function configureHeaderBuilders(
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
108
        array $builders,
109
        ContainerBuilder $container
110
    ): self {
111 30
        foreach ($builders as $action => $value) {
112 30
            $container->setAlias(
113 30
                'innmind_rest_server.response.header_builder.'.$action,
114
                $value
115
            );
116
        }
117
118 30
        return $this;
119
    }
120
}
121