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

Issuer::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

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