Completed
Push — master ( 0563c6...cb42e4 )
by Yann
02:20
created

TokenConfigurationFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 39
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 29 2
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\DependencyInjection\Factory;
4
5
use BadMethodCallException;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Definition;
8
use Symfony\Component\DependencyInjection\Reference;
9
use Yokai\SecurityTokenBundle\Configuration\TokenConfiguration;
10
11
/**
12
 * @author Yann Eugoné <[email protected]>
13
 */
14
class TokenConfigurationFactory
15
{
16
    /**
17
     * @param string           $purpose
18
     * @param string           $generator
19
     * @param integer          $duration
20
     * @param integer          $usages
21
     * @param ContainerBuilder $container
22
     */
23 3
    public static function create($purpose, $generator, $duration, $usages, ContainerBuilder $container)
24
    {
25 3
        $id = sprintf('yokai_security_token.configuration.%s', $purpose);
26
27 3
        if ($container->hasDefinition($id)) {
28
            throw new BadMethodCallException(
29
                sprintf(
30
                    'Cannot register service for security token on "%s" purpose.'.
31
                    ' A service with id "%s" is already registered.',
32
                    $purpose,
33
                    $id
34
                )
35
            );
36
        }
37
38 3
        $definition = new Definition(
39 3
            TokenConfiguration::class,
40
            [
41 3
                $purpose,
42 3
                new Reference($generator),
43 3
                $duration,
44 3
                $usages
45
            ]
46
        );
47
48 3
        $definition->addTag('yokai_security_token.configuration');
49
50 3
        $container->setDefinition($id, $definition);
51 3
    }
52
}
53