AbstractGrantType   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A issueAccessToken() 0 10 1
A issueRefreshToken() 0 6 1
A issueTokens() 0 6 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Alexandre
5
 * Date: 11/03/2018
6
 * Time: 17:56
7
 */
8
9
namespace OAuth2\AuthorizationGrantTypes;
10
11
12
use OAuth2\Storages\AccessTokenStorageInterface;
13
use OAuth2\Storages\RefreshTokenStorageInterface;
14
15
abstract class AbstractGrantType implements GrantTypeInterface
16
{
17
    /**
18
     * @var AccessTokenStorageInterface
19
     */
20
    protected $accessTokenStorage;
21
    /**
22
     * @var RefreshTokenStorageInterface
23
     */
24
    protected $refreshTokenStorage;
25
26
    public function __construct(AccessTokenStorageInterface $accessTokenStorage,
27
                                RefreshTokenStorageInterface $refreshTokenStorage)
28
    {
29
        $this->accessTokenStorage = $accessTokenStorage;
30
        $this->refreshTokenStorage = $refreshTokenStorage;
31
    }
32
33
    protected function issueTokens(array $scopes, string $clientIdentifier, ?string $resourceOwnerIdentifier = null,
34
                                   ?string $authorizationCode = null)
35
    {
36
        return array_merge(
37
            $this->issueAccessToken($scopes, $clientIdentifier, $resourceOwnerIdentifier, $authorizationCode),
38
            $this->issueRefreshToken($scopes, $clientIdentifier, $resourceOwnerIdentifier, $authorizationCode)
39
        );
40
    }
41
42
    protected function issueAccessToken(array $scopes, string $clientIdentifier,
43
                                        ?string $resourceOwnerIdentifier = null, ?string $authorizationCode = null): array
44
    {
45
        $accessToken = $this->accessTokenStorage->generate($scopes, $clientIdentifier,
46
            $resourceOwnerIdentifier, $authorizationCode);
47
48
        return [
49
            'access_token' => $accessToken->getToken(),
50
            'token_type' => $accessToken->getType(),
0 ignored issues
show
Bug introduced by
The method getType() does not exist on OAuth2\Credentials\TokenInterface. It seems like you code against a sub-type of OAuth2\Credentials\TokenInterface such as OAuth2\Credentials\AccessTokenInterface or OAuth2\Credentials\AccessToken. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            'token_type' => $accessToken->/** @scrutinizer ignore-call */ getType(),
Loading history...
51
            'expires_in' => $this->accessTokenStorage->getLifetime()
52
        ];
53
    }
54
55
    protected function issueRefreshToken(array $scopes, string $clientIdentifier,
56
                                         ?string $resourceOwnerIdentifier = null, ?string $authorizationCode = null)
57
    {
58
        $accessToken = $this->refreshTokenStorage->generate($scopes, $clientIdentifier, $resourceOwnerIdentifier, $authorizationCode);
59
        return [
60
            'refresh_token' => $accessToken->getToken()
61
        ];
62
    }
63
}