AccessTokenRepository::getNewToken()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
crap 2
1
<?php
2
3
4
namespace Mvdstam\Oauth2ServerLaravel\Repositories;
5
6
7
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
8
use League\OAuth2\Server\Entities\ClientEntityInterface;
9
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
10
use Mvdstam\Oauth2ServerLaravel\Entities\AccessToken;
11
12
13
class AccessTokenRepository extends AbstractRepository implements AccessTokenRepositoryInterface
14
{
15 14
    public function model()
16
    {
17 14
        return AccessTokenEntityInterface::class;
18
    }
19
20 10
    public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
21
    {
22
        /** @var AccessTokenEntityInterface $accessToken */
23 10
        $accessToken = $this->makeModel(false);
24
25 10
        $accessToken->setClient($clientEntity);
26
27 10
        array_map([$accessToken, 'addScope'], $scopes);
28
29 10
        if (!is_null($userIdentifier)) {
30 4
            $accessToken->setUserIdentifier($userIdentifier);
31
        }
32
33 10
        return $accessToken;
34
    }
35
36 10 View Code Duplication
    public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        /** @var AccessToken $accessToken */
39 10
        $accessToken = $this->makeModel(false);
40
41 10
        $accessToken->forceFill([
42 10
            'id' => $accessTokenEntity->getIdentifier(),
43 10
            'expires_at' => $accessTokenEntity->getExpiryDateTime(),
44 10
            'user_id' => $accessTokenEntity->getUserIdentifier(),
45 10
            'client_id' => $accessTokenEntity->getClient()->getIdentifier()
46
        ]);
47
48 10
        array_map([$accessToken, 'addScope'], $accessTokenEntity->getScopes());
49
50 10
        $accessToken->save();
51
52 10
        return $accessToken;
53
    }
54
55 2
    public function revokeAccessToken($tokenId)
56
    {
57 2
        $this->delete($tokenId);
58 2
    }
59
60 4
    public function isAccessTokenRevoked($tokenId)
61
    {
62 4
        return empty($this->find($tokenId));
63
    }
64
65
}
66