Failed Conditions
Push — ng ( 03dae5...ac104a )
by Florent
04:27
created

TrustedIssuerManager::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\Component\Server\TokenEndpoint\AuthenticationMethod;
15
16
final class TrustedIssuerManager
17
{
18
    /**
19
     * @var TrustedIssuer[]
20
     */
21
    private $trustedIssuers = [];
22
23
    /**
24
     * @param TrustedIssuer $trustedIssuer
25
     */
26
    public function add(TrustedIssuer $trustedIssuer)
27
    {
28
        $this->trustedIssuers[$trustedIssuer->name()] = $trustedIssuer;
29
    }
30
31
    /**
32
     * @param string $issuer
33
     *
34
     * @return bool
35
     */
36
    public function has(string $issuer): bool
37
    {
38
        return array_key_exists($issuer, $this->trustedIssuers);
39
    }
40
41
    /**
42
     * @param string $issuer
43
     *
44
     * @return TrustedIssuer
45
     */
46
    public function get(string $issuer): TrustedIssuer
47
    {
48
        if (!$this->has($issuer)) {
49
            throw new \InvalidArgumentException(sprintf('The issuer "%s" is not known.', $issuer));
50
        }
51
52
        return $this->trustedIssuers[$issuer];
53
    }
54
}
55