AuthenticatedUserAwareTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setUserFromSecurityTokenStorage() 0 12 3
1
<?php
2
namespace AppBundle\Security;
3
4
use AppBundle\Entity\User;
5
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
6
7
trait AuthenticatedUserAwareTrait
8
{
9
    /** @var \AppBundle\Entity\User */
10
    protected $authenticatedUser;
11
12
    public function setUserFromSecurityTokenStorage(TokenStorageInterface $tokenStorage)
13
    {
14
        if (($token = $tokenStorage->getToken()) === null) {
15
            throw new \InvalidArgumentException('Token missing');
16
        }
17
18
        if (!(($user = $token->getUser()) instanceof User)) {
19
            throw new \InvalidArgumentException('Invalid user');
20
        }
21
22
        $this->authenticatedUser = $user;
23
    }
24
}
25