GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch php72 (880eb0)
by Joni
05:58
created

PublicKeyJWK   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 39
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromPublicKey() 0 9 3
A fromPublicKeyInfo() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\JWX\JWK\Asymmetric;
6
7
use Sop\CryptoEncoding\PEM;
8
use Sop\CryptoTypes\Asymmetric\EC\ECPublicKey;
9
use Sop\CryptoTypes\Asymmetric\PublicKey;
10
use Sop\CryptoTypes\Asymmetric\PublicKeyInfo;
11
use Sop\CryptoTypes\Asymmetric\RSA\RSAPublicKey;
12
use Sop\JWX\JWK\EC\ECPublicKeyJWK;
13
use Sop\JWX\JWK\JWK;
14
use Sop\JWX\JWK\RSA\RSAPublicKeyJWK;
15
16
/**
17
 * Base class for JWK public keys of an asymmetric key pairs.
18
 */
19
abstract class PublicKeyJWK extends JWK
20
{
21
    /**
22
     * Convert public key to PEM.
23
     *
24
     * @return PEM
25
     */
26
    abstract public function toPEM(): PEM;
27
28
    /**
29
     * Initialize from a PublicKey object.
30
     *
31
     * @param PublicKey $pub_key Public key
32
     *
33
     * @throws \UnexpectedValueException
34
     *
35
     * @return self
36
     */
37 3
    public static function fromPublicKey(PublicKey $pub_key): PublicKeyJWK
38
    {
39 3
        if ($pub_key instanceof RSAPublicKey) {
40 1
            return RSAPublicKeyJWK::fromRSAPublicKey($pub_key);
41
        }
42 2
        if ($pub_key instanceof ECPublicKey) {
43 1
            return ECPublicKeyJWK::fromECPublicKey($pub_key);
44
        }
45 1
        throw new \UnexpectedValueException('Unsupported public key.');
46
    }
47
48
    /**
49
     * Initialize from a PublicKeyInfo object.
50
     *
51
     * @param PublicKeyInfo $pki Public key info
52
     *
53
     * @return self
54
     */
55 2
    public static function fromPublicKeyInfo(PublicKeyInfo $pki): PublicKeyJWK
56
    {
57 2
        return self::fromPublicKey($pki->publicKey());
58
    }
59
}
60