Failed Conditions
Push — master ( 1bae70...6a9de1 )
by Florent
40:14
created

SymfonyUserAccountDiscovery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCurrentAccount() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\ServerBundle\Tests\TestBundle\Service;
15
16
use OAuth2Framework\Component\AuthorizationEndpoint\User\UserAccountDiscovery;
17
use OAuth2Framework\Component\Core\UserAccount\UserAccount;
18
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
19
20
final class SymfonyUserAccountDiscovery implements UserAccountDiscovery
21
{
22
    private $tokenStorage;
23
24
    public function __construct(TokenStorageInterface $tokenStorage)
25
    {
26
        $this->tokenStorage = $tokenStorage;
27
    }
28
29
    public function getCurrentAccount(): ?UserAccount
30
    {
31
        $token = $this->tokenStorage->getToken();
32
        if (null === $token) {
33
            throw new \InvalidArgumentException('Unable to retrieve the current user.');
34
        }
35
36
        $user = $token->getUser();
37
        if (!$user instanceof UserAccount) {
38
            throw new \InvalidArgumentException('Unable to retrieve the current user.');
39
        }
40
41
        return $user;
42
    }
43
}
44