Completed
Push — master ( 704578...e88511 )
by Alex
32:19
created

AccessTokenRepository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
c 2
b 1
f 0
lcom 0
cbo 1
dl 0
loc 41
rs 10

4 Methods

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