Issuer::getJwks()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\OpenIdClient\Issuer;
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\Issuer\Metadata\IssuerMetadataInterface;
12
13
final 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 4
    public function __construct(
25
        IssuerMetadataInterface $metadata,
26
        JWKSet $jwks,
27
        ?JKUFactory $JKUFactory = null
28
    ) {
29 4
        $this->metadata = $metadata;
30 4
        $this->jwks = $jwks;
31 4
        $this->JKUFactory = $JKUFactory ?: new JKUFactory(
32 1
            Psr18ClientDiscovery::find(),
33 1
            Psr17FactoryDiscovery::findRequestFactory()
34
        );
35 4
    }
36
37 3
    public function getMetadata(): IssuerMetadataInterface
38
    {
39 3
        return $this->metadata;
40
    }
41
42
    /**
43
     * @return JWKSet
44
     */
45 2
    public function getJwks(): JWKSet
46
    {
47 2
        return $this->jwks;
48
    }
49
50 1
    public function updateJwks(): void
51
    {
52 1
        $this->jwks = $this->JKUFactory->loadFromUrl($this->metadata->getJwksUri());
53 1
    }
54
}
55