Completed
Pull Request — master (#16)
by Yann
13:51
created

TokenFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 6

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 2
cbo 6
dl 0
loc 52
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A create() 0 16 1
1
<?php
2
3
namespace Yokai\SecurityTokenBundle\Factory;
4
5
use Yokai\SecurityTokenBundle\Configuration\TokenConfigurationRegistry;
6
use Yokai\SecurityTokenBundle\Entity\Token;
7
use Yokai\SecurityTokenBundle\InformationGuesser\InformationGuesserInterface;
8
use Yokai\SecurityTokenBundle\Manager\UserManagerInterface;
9
10
/**
11
 * @author Yann Eugoné <[email protected]>
12
 */
13
class TokenFactory implements TokenFactoryInterface
14
{
15
    /**
16
     * @var TokenConfigurationRegistry
17
     */
18
    private $registry;
19
20
    /**
21
     * @var InformationGuesserInterface
22
     */
23
    private $informationGuesser;
24
25
    /**
26
     * @var UserManagerInterface
27
     */
28
    private $userManager;
29
30
    /**
31
     * @param TokenConfigurationRegistry  $registry
32
     * @param InformationGuesserInterface $informationGuesser
33
     * @param UserManagerInterface        $userManager
34
     */
35 1
    public function __construct(
36
        TokenConfigurationRegistry $registry,
37
        InformationGuesserInterface $informationGuesser,
38
        UserManagerInterface $userManager
39
    ) {
40 1
        $this->registry = $registry;
41 1
        $this->informationGuesser = $informationGuesser;
42 1
        $this->userManager = $userManager;
43 1
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48 1
    public function create($user, $purpose, array $payload = [])
49
    {
50 1
        $configuration = $this->registry->get($purpose);
51
52 1
        return new Token(
53 1
            $this->userManager->getClass($user),
54 1
            $this->userManager->getId($user),
55 1
            $configuration->getGenerator()->generate(),
56
            $purpose,
57 1
            $configuration->getDuration(),
58 1
            $configuration->getKeep(),
59 1
            $configuration->getUsages(),
60
            $payload,
61 1
            $this->informationGuesser->get()
62
        );
63
    }
64
}
65