AccessTokenRepository::getNewToken()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 3
dl 0
loc 15
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author      Alex Bilbie <[email protected]>
5
 * @copyright   Copyright (c) Alex Bilbie
6
 * @license     http://mit-license.org/
7
 *
8
 * @link        https://github.com/thephpleague/oauth2-server
9
 */
10
11
declare(strict_types=1);
12
13
namespace OAuth2ServerExamples\Repositories;
14
15
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
16
use League\OAuth2\Server\Entities\ClientEntityInterface;
17
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
18
use OAuth2ServerExamples\Entities\AccessTokenEntity;
19
20
class AccessTokenRepository implements AccessTokenRepositoryInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity): void
26
    {
27
        // Some logic here to save the access token to a database
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function revokeAccessToken($tokenId): void
34
    {
35
        // Some logic here to revoke the access token
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function isAccessTokenRevoked($tokenId): bool
42
    {
43
        return false; // Access token hasn't been revoked
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null): AccessTokenEntityInterface
50
    {
51
        $accessToken = new AccessTokenEntity();
52
53
        $accessToken->setClient($clientEntity);
54
55
        foreach ($scopes as $scope) {
56
            $accessToken->addScope($scope);
57
        }
58
59
        if ($userIdentifier !== null) {
60
            $accessToken->setUserIdentifier((string) $userIdentifier);
61
        }
62
63
        return $accessToken;
64
    }
65
}
66