GrantContext   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 35
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getGrantType() 0 6 2
A removeGrantType() 0 3 1
A addGrantType() 0 3 1
1
<?php
2
3
namespace kalanis\OAuth2\Grant;
4
5
6
use kalanis\OAuth2\Exceptions\InvalidStateException;
7
8
9
/**
10
 * GrantContext
11
 * @package kalanis\OAuth2\Grant
12
 */
13
class GrantContext
14
{
15
16
    /** @var array<IGrant> */
17
    private array $grantTypes = [];
18
19
    /**
20
     * Add grant type
21
     */
22
    public function addGrantType(IGrant $grantType): void
23
    {
24
        $this->grantTypes[$grantType->getIdentifier()] = $grantType;
25
    }
26
27
    /**
28
     * Remove grant type from strategy context
29
     * @param string $grantType
30
     */
31
    public function removeGrantType(string $grantType): void
32
    {
33
        unset($this->grantTypes[$grantType]);
34
    }
35
36
    /**
37
     * Get grant type
38
     * @param string $grantType
39
     * @throws InvalidStateException
40
     * @return IGrant
41
     */
42
    public function getGrantType(string $grantType): IGrant
43
    {
44
        if (!isset($this->grantTypes[$grantType])) {
45
            throw new InvalidStateException('Grant type ' . $grantType . ' is not registered in GrantContext');
46
        }
47
        return $this->grantTypes[$grantType];
48
    }
49
}
50