Session   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 0
loc 76
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getByAccessToken() 0 14 2
A getByAuthCode() 0 4 1
A getScopes() 0 8 1
A create() 0 4 1
A associateScope() 0 4 1
1
<?php
2
3
namespace Eole\Sandstone\OAuth2\Storage;
4
5
use League\OAuth2\Server\Entity\SessionEntity;
6
use League\OAuth2\Server\Entity\AccessTokenEntity;
7
use League\OAuth2\Server\Entity\AuthCodeEntity;
8
use League\OAuth2\Server\Entity\ScopeEntity;
9
use League\OAuth2\Server\Storage\AbstractStorage;
10
use League\OAuth2\Server\Storage\SessionInterface;
11
12
class Session extends AbstractStorage implements SessionInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    private $accessTokensDir;
18
19
    /**
20
     * @var string[]
21
     */
22
    private $scope;
23
24
    /**
25
     * @param string $accessTokensDir
26
     * @param string[] $scope
27
     */
28
    public function __construct($accessTokensDir, array $scope)
29
    {
30
        $this->accessTokensDir = $accessTokensDir;
31
        $this->scope = $scope;
32
    }
33
34
    /**
35
     * {@InheritDoc}
36
     */
37
    public function getByAccessToken(AccessTokenEntity $accessToken)
38
    {
39
        if (!file_exists($this->accessTokensDir.'/'.$accessToken->getId())) {
40
            return null;
41
        }
42
43
        $tokenContent = explode('-', file_get_contents($this->accessTokensDir.'/'.$accessToken->getId()));
44
        $sessionId = $tokenContent[0];
45
46
        $session = new SessionEntity($this->server);
47
        $session->setId($sessionId);
48
49
        return $session;
50
    }
51
52
    /**
53
     * {@InheritDoc}
54
     */
55
    public function getByAuthCode(AuthCodeEntity $authCode)
56
    {
57
        throw new \Eole\Sandstone\OAuth2\Exception\NotImplementedException();
58
    }
59
60
    /**
61
     * {@InheritDoc}
62
     */
63
    public function getScopes(SessionEntity $session)
64
    {
65
        $scope = new ScopeEntity($this->server);
66
67
        $scope->hydrate($this->scope);
68
69
        return array($scope);
70
    }
71
72
    /**
73
     * {@InheritDoc}
74
     */
75
    public function create($ownerType, $ownerId, $clientId, $clientRedirectUri = null)
76
    {
77
        return $ownerId;
78
    }
79
80
    /**
81
     * {@InheritDoc}
82
     */
83
    public function associateScope(SessionEntity $session, ScopeEntity $scope)
84
    {
85
        $session->associateScope($scope);
86
    }
87
}
88