TokenContext::addToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\OAuth2\Storage;
4
5
6
use kalanis\OAuth2\Exceptions\InvalidStateException;
7
8
9
/**
10
 * TokenContext
11
 * @package kalanis\OAuth2\Storage
12
 */
13
class TokenContext
14
{
15
    /** @var array<ITokenFacade> */
16
    private array $tokens = [];
17
18
    /**
19
     * Add identifier to collection
20
     */
21
    public function addToken(ITokenFacade $token): void
22
    {
23 1
        $this->tokens[$token->getIdentifier()] = $token;
24 1
    }
25
26
    /**
27
     * Get token
28
     * @param string $identifier
29
     * @throws InvalidStateException
30
     * @return ITokenFacade
31
     */
32
    public function getToken(string $identifier): ITokenFacade
33
    {
34 1
        if (!isset($this->tokens[$identifier])) {
35 1
            throw new InvalidStateException('Token called "' . $identifier . '" not found in Token context');
36
        }
37
38 1
        return $this->tokens[$identifier];
39
    }
40
}
41