AccessToken   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 27.4 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 20
loc 73
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 20 20 2
A getScopes() 0 4 1
A create() 0 4 1
A associateScope() 0 4 1
A delete() 0 6 2

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
namespace Eole\Sandstone\OAuth2\Storage;
4
5
use League\OAuth2\Server\Entity\AccessTokenEntity;
6
use League\OAuth2\Server\Entity\ScopeEntity;
7
use League\OAuth2\Server\Entity\SessionEntity;
8
use League\OAuth2\Server\Storage\AccessTokenInterface;
9
use League\OAuth2\Server\Storage\AbstractStorage;
10
11
class AccessToken extends AbstractStorage implements AccessTokenInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $accessTokensDir;
17
18
    /**
19
     * @param string $accessTokensDir
20
     */
21
    public function __construct($accessTokensDir)
22
    {
23
        $this->accessTokensDir = $accessTokensDir;
24
    }
25
26
    /**
27
     * {@InheritDoc}
28
     */
29 View Code Duplication
    public function get($token)
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...
30
    {
31
        if (!file_exists($this->accessTokensDir.'/'.$token)) {
32
            return null;
33
        }
34
35
        $tokenContent = explode('-', file_get_contents($this->accessTokensDir.'/'.$token));
36
        $sessionId = $tokenContent[0];
37
        $expireTime = $tokenContent[1];
38
39
        $session = new SessionEntity($this->server);
40
        $session->setId($sessionId);
41
42
        $accessToken = new AccessTokenEntity($this->server);
43
        $accessToken->setId($token);
44
        $accessToken->setExpireTime(intval($expireTime));
45
        $accessToken->setSession($session);
46
47
        return $accessToken;
48
    }
49
50
    /**
51
     * {@InheritDoc}
52
     */
53
    public function getScopes(AccessTokenEntity $token)
54
    {
55
        throw new \Eole\Sandstone\OAuth2\Exception\NotImplementedException();
56
    }
57
58
    /**
59
     * {@InheritDoc}
60
     */
61
    public function create($token, $expireTime, $sessionId)
62
    {
63
        file_put_contents($this->accessTokensDir.'/'.$token, $sessionId.'-'.$expireTime);
64
    }
65
66
    /**
67
     * {@InheritDoc}
68
     */
69
    public function associateScope(AccessTokenEntity $token, ScopeEntity $scope)
70
    {
71
        $token->associateScope($scope);
72
    }
73
74
    /**
75
     * {@InheritDoc}
76
     */
77
    public function delete(AccessTokenEntity $token)
78
    {
79
        if (file_exists($this->accessTokensDir.'/'.$token->getId())) {
80
            unlink($this->accessTokensDir.'/'.$token->getId());
81
        }
82
    }
83
}
84