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.

PublicKeyJWK::fromPublicKeyInfo()   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
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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
    abstract public function toPEM(): PEM;
25
26
    /**
27
     * Initialize from a PublicKey object.
28
     *
29
     * @param PublicKey $pub_key Public key
30
     *
31
     * @throws \UnexpectedValueException
32
     *
33
     * @return self
34
     */
35 3
    public static function fromPublicKey(PublicKey $pub_key): PublicKeyJWK
36
    {
37 3
        if ($pub_key instanceof RSAPublicKey) {
38 1
            return RSAPublicKeyJWK::fromRSAPublicKey($pub_key);
39
        }
40 2
        if ($pub_key instanceof ECPublicKey) {
41 1
            return ECPublicKeyJWK::fromECPublicKey($pub_key);
42
        }
43 1
        throw new \UnexpectedValueException('Unsupported public key.');
44
    }
45
46
    /**
47
     * Initialize from a PublicKeyInfo object.
48
     *
49
     * @param PublicKeyInfo $pki Public key info
50
     *
51
     * @return self
52
     */
53 2
    public static function fromPublicKeyInfo(PublicKeyInfo $pki): PublicKeyJWK
54
    {
55 2
        return self::fromPublicKey($pki->publicKey());
56
    }
57
}
58