TokenConfigurationRegistry   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
cbo 1
dl 0
loc 34
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A get() 0 10 2
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Configuration;
4
5
use BadMethodCallException;
6
7
/**
8
 * @author Yann Eugoné <[email protected]>
9
 */
10
class TokenConfigurationRegistry
11
{
12
    /**
13
     * @var TokenConfiguration[]
14
     */
15
    private $configurations;
16
17
    /**
18
     * @param TokenConfiguration[] $configurations
19
     */
20 3
    public function __construct(array $configurations)
21
    {
22 3
        $this->configurations = [];
23 3
        foreach ($configurations as $configuration) {
24 3
            $this->configurations[$configuration->getPurpose()] = $configuration;
25
        }
26 3
    }
27
28
    /**
29
     * @param string $purpose
30
     *
31
     * @return TokenConfiguration
32
     */
33 3
    public function get($purpose)
34
    {
35 3
        if (!isset($this->configurations[$purpose])) {
36
            throw new BadMethodCallException(
37
                sprintf('There is no configured security token on "%s" purpose.', $purpose)
38
            );
39
        }
40
41 3
        return $this->configurations[$purpose];
42
    }
43
}
44