Completed
Push — master ( 24b9f5...f17bc4 )
by Florent
02:53
created

CompressionCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 7
Bugs 3 Features 0
Metric Value
wmc 4
c 7
b 3
f 0
lcom 0
cbo 4
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 18 4
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace SpomkyLabs\JoseBundle\DependencyInjection\Compiler;
13
14
use Assert\Assertion;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
final class CompressionCompilerPass implements CompilerPassInterface
20
{
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (!$container->hasDefinition('jose.compression_manager')) {
24
            return;
25
        }
26
27
        $loaded = [];
28
        $definition = $container->getDefinition('jose.compression_manager');
29
30
        $taggedServices = $container->findTaggedServiceIds('jose_compression');
31
        foreach ($taggedServices as $id => $tags) {
32
            foreach ($tags as $attributes) {
33
                Assertion::keyExists($attributes, 'alias', sprintf("The compression method '%s' does not have any 'alias' attribute.", $id));
34
                $loaded[] = $attributes['alias'];
35
                $definition->addMethodCall('addCompressionAlgorithm', [new Reference($id)]);
36
            }
37
        }
38
    }
39
}
40