Passed
Push — master ( c8bc96...3cc4a7 )
by Thomas Mauro
06:51
created

Issuer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 53.85%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 47
ccs 7
cts 13
cp 0.5385
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadata() 0 3 1
A updateJwks() 0 3 1
A getJwks() 0 3 1
A __construct() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient;
6
7
use Http\Discovery\Psr17FactoryDiscovery;
8
use Http\Discovery\Psr18ClientDiscovery;
9
use Jose\Component\Core\JWKSet;
10
use Jose\Component\KeyManagement\JKUFactory;
11
use TMV\OpenIdClient\Model\IssuerMetadataInterface;
12
13
class Issuer implements IssuerInterface
14
{
15
    /** @var IssuerMetadataInterface */
16
    private $metadata;
17
18
    /** @var JWKSet */
19
    private $jwks;
20
21
    /** @var JKUFactory */
22
    private $JKUFactory;
23
24
    /**
25
     * Issuer constructor.
26
     *
27
     * @param IssuerMetadataInterface $metadata
28
     * @param JWKSet $jwks
29
     * @param JKUFactory|null $JKUFactory
30
     */
31 2
    public function __construct(
32
        IssuerMetadataInterface $metadata,
33
        JWKSet $jwks,
34
        ?JKUFactory $JKUFactory = null
35
    ) {
36 2
        $this->metadata = $metadata;
37 2
        $this->jwks = $jwks;
38 2
        $this->JKUFactory = $JKUFactory ?: new JKUFactory(
39
            Psr18ClientDiscovery::find(),
40
            Psr17FactoryDiscovery::findRequestFactory()
41
        );
42 2
    }
43
44 2
    public function getMetadata(): IssuerMetadataInterface
45
    {
46 2
        return $this->metadata;
47
    }
48
49
    /**
50
     * @return JWKSet
51
     */
52
    public function getJwks(): JWKSet
53
    {
54
        return $this->jwks;
55
    }
56
57
    public function updateJwks(): void
58
    {
59
        $this->jwks = $this->JKUFactory->loadFromUrl($this->metadata->getJwksUri());
60
    }
61
}
62