Memory   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 17
lcom 2
cbo 2
dl 0
loc 128
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A retrieveAccessToken() 0 8 2
A storeAccessToken() 0 7 1
A hasAccessToken() 0 4 2
A clearToken() 0 9 2
A clearAllTokens() 0 7 1
A retrieveAuthorizationState() 0 8 2
A storeAuthorizationState() 0 7 1
A hasAuthorizationState() 0 4 2
A clearAuthorizationState() 0 9 2
A clearAllAuthorizationStates() 0 7 1
1
<?php
2
3
namespace OAuth\Common\Storage;
4
5
use OAuth\Common\Storage\Exception\AuthorizationStateNotFoundException;
6
use OAuth\Common\Storage\Exception\TokenNotFoundException;
7
use OAuth\Common\Token\TokenInterface;
8
9
// Stores a token in-memory only (destroyed at end of script execution).
10
class Memory implements TokenStorageInterface
11
{
12
    /**
13
     * @var object|TokenInterface
14
     */
15
    protected $tokens;
16
17
    /**
18
     * @var array
19
     */
20
    protected $states;
21
22
    public function __construct()
23
    {
24
        $this->tokens = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type object of property $tokens.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
25
        $this->states = [];
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function retrieveAccessToken($service)
32
    {
33
        if ($this->hasAccessToken($service)) {
34
            return $this->tokens[$service];
35
        }
36
37
        throw new TokenNotFoundException('Token not stored');
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function storeAccessToken($service, TokenInterface $token)
44
    {
45
        $this->tokens[$service] = $token;
46
47
        // allow chaining
48
        return $this;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function hasAccessToken($service)
55
    {
56
        return isset($this->tokens[$service]) && $this->tokens[$service] instanceof TokenInterface;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function clearToken($service)
63
    {
64
        if (array_key_exists($service, $this->tokens)) {
65
            unset($this->tokens[$service]);
66
        }
67
68
        // allow chaining
69
        return $this;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function clearAllTokens()
76
    {
77
        $this->tokens = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type object of property $tokens.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
78
79
        // allow chaining
80
        return $this;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function retrieveAuthorizationState($service)
87
    {
88
        if ($this->hasAuthorizationState($service)) {
89
            return $this->states[$service];
90
        }
91
92
        throw new AuthorizationStateNotFoundException('State not stored');
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function storeAuthorizationState($service, $state)
99
    {
100
        $this->states[$service] = $state;
101
102
        // allow chaining
103
        return $this;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function hasAuthorizationState($service)
110
    {
111
        return isset($this->states[$service]) && null !== $this->states[$service];
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function clearAuthorizationState($service)
118
    {
119
        if (array_key_exists($service, $this->states)) {
120
            unset($this->states[$service]);
121
        }
122
123
        // allow chaining
124
        return $this;
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function clearAllAuthorizationStates()
131
    {
132
        $this->states = [];
133
134
        // allow chaining
135
        return $this;
136
    }
137
}
138