UserFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 45
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUserClass() 0 4 1
A build() 0 4 1
A getUserClass() 0 4 1
A refreshUser() 0 10 2
1
<?php
2
/**
3
 * File part of the Redmine User Provider bundle
4
 *
5
 * @category  SymfonyBundle
6
 * @package   GMaissa.RedmineUserProviderBundle
7
 * @author    Guillaume Maïssa <[email protected]>
8
 * @copyright 2017 Guillaume Maïssa
9
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
10
 */
11
12
namespace GMaissa\RedmineUserProviderBundle\Factory;
13
14
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
15
use Symfony\Component\Security\Core\User\UserInterface;
16
17
/**
18
 * User factory class
19
 */
20
class UserFactory implements UserFactoryInterface
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $userClass;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 8
    public function setUserClass(string $class)
31
    {
32 8
        $this->userClass = $class;
33 8
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function build(array $data = null): UserInterface
39
    {
40 3
        return new $this->userClass($data);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function getUserClass(): string
47
    {
48 2
        return $this->userClass;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 2
    public function refreshUser(UserInterface $user): UserInterface
55
    {
56 2
        if (!$user instanceof $this->userClass) {
57 2
            throw new UnsupportedUserException(
58 2
                sprintf('Instances of "%s" are not supported.', get_class($user))
59
            );
60
        }
61
62 2
        return $user;
63
    }
64
}
65