TokenConfig   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 90
ccs 0
cts 44
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getKey() 0 12 3
A getAllKeys() 0 4 1
A getClientId() 0 4 1
A getRedirectUrl() 0 4 1
A getScopes() 0 4 1
A getSecret() 0 4 1
A getApplicationName() 0 4 1
1
<?php
2
3
namespace Happyr\GoogleSiteAuthenticatorBundle\Model;
4
5
/**
6
 * This class holds all the tokens' configuration.
7
 */
8
class TokenConfig
9
{
10
    const APPLICATION_NAME = 'GoogleAuthenticator';
11
12
    private $tokens;
13
14
    /**
15
     * @var string defaultKey
16
     */
17
    private $defaultKey;
18
19
    /**
20
     * @param array $tokens
21
     */
22
    public function __construct(array $tokens)
23
    {
24
        $this->tokens = $tokens;
25
26
        if (isset($tokens['default'])) {
27
            $this->defaultKey = 'default';
28
        } else {
29
            // take the first key
30
            reset($tokens);
31
            $this->defaultKey = key($tokens);
32
        }
33
    }
34
35
    /**
36
     * Get the key from the argument or the default key.
37
     */
38
    public function getKey(string $key = null): string
39
    {
40
        if ($key === null) {
41
            return $this->defaultKey;
42
        }
43
44
        if (!isset($this->tokens[$key])) {
45
            throw new \LogicException(sprintf('Token with name %s could not be found', $key));
46
        }
47
48
        return $key;
49
    }
50
51
    /**
52
     * Get all keys.
53
     *
54
     * @return array
55
     */
56
    public function getAllKeys(): array
57
    {
58
        return array_keys($this->tokens);
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getClientId(string $tokenName = null)
65
    {
66
        return $this->tokens[$this->getKey($tokenName)]['client_id'];
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getRedirectUrl($tokenName = null)
73
    {
74
        return $this->tokens[$this->getKey($tokenName)]['redirect_url'];
75
    }
76
77
    /**
78
     * @return array
79
     */
80
    public function getScopes($tokenName = null)
81
    {
82
        return $this->tokens[$this->getKey($tokenName)]['scopes'];
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getSecret($tokenName = null)
89
    {
90
        return $this->tokens[$this->getKey($tokenName)]['client_secret'];
91
    }
92
93
    public function getApplicationName(): string
94
    {
95
        return self::APPLICATION_NAME;
96
    }
97
}
98