Completed
Push — master ( ead5e5...fe31fe )
by Yann
02:34
created

TokenConfigurationFactory::create()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2.0078

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 14
cts 16
cp 0.875
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 19
nc 2
nop 7
crap 2.0078
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 string           $duration
20
     * @param integer          $usages
21
     * @param string           $keep
22
     * @param boolean          $unique
23
     * @param ContainerBuilder $container
24
     */
25 3
    public static function create($purpose, $generator, $duration, $usages, $keep, $unique, ContainerBuilder $container)
26
    {
27 3
        $id = sprintf('yokai_security_token.configuration.%s', $purpose);
28
29 3
        if ($container->hasDefinition($id)) {
30
            throw new BadMethodCallException(
31
                sprintf(
32
                    'Cannot register service for security token on "%s" purpose.'.
33
                    ' A service with id "%s" is already registered.',
34
                    $purpose,
35
                    $id
36
                )
37
            );
38
        }
39
40 3
        $definition = new Definition(
41 3
            TokenConfiguration::class,
42
            [
43 3
                $purpose,
44 3
                new Reference($generator),
45 3
                $duration,
46 3
                $usages,
47 3
                $keep,
48 3
                $unique
49
            ]
50
        );
51
52 3
        $definition->addTag('yokai_security_token.configuration');
53
54 3
        $container->setDefinition($id, $definition);
55 3
    }
56
}
57