GrantContext::removeGrantType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
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