Failed Conditions
Push — master ( 349866...67c1d1 )
by Florent
10:56 queued 06:08
created

AccessTokenResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A supports() 0 8 2
A resolve() 0 7 2
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\SecurityBundle\Resolver;
15
16
use OAuth2Framework\SecurityBundle\Security\Authentication\Token\OAuth2Token;
17
use OAuth2Framework\Component\Core\AccessToken\AccessToken;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
20
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
21
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
22
23
final class AccessTokenResolver implements ArgumentValueResolverInterface
24
{
25
    /**
26
     * @var TokenStorageInterface
27
     */
28
    private $tokenStorage;
29
30
    /**
31
     * AccessTokenResolver constructor.
32
     *
33
     * @param TokenStorageInterface $tokenStorage
34
     */
35
    public function __construct(TokenStorageInterface $tokenStorage)
36
    {
37
        $this->tokenStorage = $tokenStorage;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function supports(Request $request, ArgumentMetadata $argument)
44
    {
45
        if (AccessToken::class !== $argument->getType()) {
46
            return false;
47
        }
48
49
        return $this->tokenStorage->getToken() instanceof OAuth2Token;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function resolve(Request $request, ArgumentMetadata $argument)
56
    {
57
        $token = $this->tokenStorage->getToken();
58
        if ($token instanceof OAuth2Token) {
59
            yield $token->getAccessToken();
60
        }
61
    }
62
}
63