UserProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 43
rs 10
c 3
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUser() 0 3 1
A __construct() 0 4 1
A getTeam() 0 4 1
A getPlayer() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Security;
6
7
use Doctrine\ORM\Exception\ORMException;
8
use Symfony\Bundle\SecurityBundle\Security;
9
use Symfony\Component\Security\Core\User\UserInterface;
10
use VideoGamesRecords\CoreBundle\DataTransformer\UserToPlayerTransformer;
11
use VideoGamesRecords\CoreBundle\Entity\Player;
12
use VideoGamesRecords\CoreBundle\Entity\Team;
13
14
class UserProvider
15
{
16
    private Security $security;
17
    private UserToPlayerTransformer $userToPlayerTransformer;
18
19
    /**
20
     * @param Security      $security
21
     * @param UserToPlayerTransformer $userToPlayerTransformer
22
     */
23
    public function __construct(Security $security, UserToPlayerTransformer $userToPlayerTransformer)
24
    {
25
        $this->security = $security;
26
        $this->userToPlayerTransformer = $userToPlayerTransformer;
27
    }
28
29
    /**
30
     * @return UserInterface|null
31
     */
32
    public function getUser(): ?UserInterface
33
    {
34
        return $this->security->getUser();
35
    }
36
37
    /**
38
     * @return ?Player
39
     * @throws ORMException
40
     */
41
    public function getPlayer(): ?Player
42
    {
43
        if (!$this->security->getUser()) {
44
            return null;
45
        }
46
        return $this->userToPlayerTransformer->transform($this->security->getUser());
47
    }
48
49
    /**
50
     * @return Team|null
51
     * @throws ORMException
52
     */
53
    public function getTeam(): ?Team
54
    {
55
        $player = $this->userToPlayerTransformer->transform($this->security->getUser());
56
        return $player->getTeam();
57
    }
58
}
59