UserProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 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