Failed Conditions
Pull Request — master (#47)
by Florent
06:42
created

CompressionMethodCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 18 5
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Bundle\JoseFramework\DependencyInjection\Compiler;
15
16
use Jose\Component\Encryption\Compression\CompressionMethodManagerFactory;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
/**
22
 * Class CompressionMethodCompilerPass.
23
 */
24
final class CompressionMethodCompilerPass implements CompilerPassInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasDefinition(CompressionMethodManagerFactory::class)) {
32
            return;
33
        }
34
35
        $definition = $container->getDefinition(CompressionMethodManagerFactory::class);
36
37
        $taggedAlgorithmServices = $container->findTaggedServiceIds('jose.compression_method');
38
        foreach ($taggedAlgorithmServices as $id => $tags) {
39
            foreach ($tags as $attributes) {
40
                if (!array_key_exists('alias', $attributes)) {
41
                    throw new \InvalidArgumentException(sprintf("The compression method '%s' does not have any 'alias' attribute.", $id));
42
                }
43
                $definition->addMethodCall('add', [$attributes['alias'], new Reference($id)]);
44
            }
45
        }
46
    }
47
}
48