ProviderPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 24
cts 24
cp 1
rs 9.344
c 0
b 0
f 0
cc 4
nc 5
nop 1
crap 4
1
<?php
2
3
namespace MediaMonks\SonataMediaBundle\DependencyInjection\Compiler;
4
5
use MediaMonks\SonataMediaBundle\Client\HttpClientInterface;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class ProviderPass implements CompilerPassInterface
11
{
12
    /**
13
     * @param ContainerBuilder $container
14
     */
15 4
    public function process(ContainerBuilder $container)
16
    {
17 4
        if (!$container->hasParameter('mediamonks.sonata_media.config')) {
18 1
            return;
19
        }
20
21 3
        $config = $container->getParameter('mediamonks.sonata_media.config');
22
23 3
        if (empty($config['image_constraints'])) {
24 1
            $config['image_constraints'] = [];
25
        }
26
27 3
        $taggedServices = $container->findTaggedServiceIds('sonata_media.provider');
28 3
        foreach ($taggedServices as $id => $tags) {
29 3
            $container->getDefinition($id)->addMethodCall(
30 3
                'setFilesystem',
31 3
                [new Reference('mediamonks.sonata_media.filesystem.private')]
32
            );
33 3
            $container->getDefinition($id)->addMethodCall(
34 3
                'setImageConstraintOptions',
35 3
                [$config['image_constraints']]
36
            );
37 3
            $container->getDefinition($id)->addMethodCall(
38 3
                'setTranslator',
39 3
                [new Reference('translator')]
40
            );
41 3
            $container->getDefinition($id)->addMethodCall(
42 3
                'setHttpClient',
43 3
                [new Reference(HttpClientInterface::class)]
44
            );
45 3
            $container->getDefinition($id)->addMethodCall(
46 3
                'setFileLocator',
47 3
                [new Reference('file_locator')]
48
            );
49
        }
50 3
    }
51
}
52