AccessTokenRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 33.96 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 18
loc 53
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A model() 0 4 1
A getNewToken() 0 15 2
A persistNewAccessToken() 18 18 1
A revokeAccessToken() 0 4 1
A isAccessTokenRevoked() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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