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

SymmetricKeyJWK   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 15
dl 0
loc 58
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A key() 0 3 1
A __construct() 0 11 4
A fromKey() 0 5 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\JWX\JWK\Symmetric;
6
7
use Sop\JWX\JWK\JWK;
8
use Sop\JWX\JWK\Parameter\JWKParameter;
9
use Sop\JWX\JWK\Parameter\KeyTypeParameter;
10
use Sop\JWX\JWK\Parameter\KeyValueParameter;
11
use Sop\JWX\Util\Base64;
12
13
/**
14
 * JWK containing a symmetric key.
15
 *
16
 * @see http://tools.ietf.org/html/rfc7518#section-6.4
17
 */
18
class SymmetricKeyJWK extends JWK
19
{
20
    /**
21
     * Parameter names managed by this class.
22
     *
23
     * @internal
24
     *
25
     * @var string[]
26
     */
27
    const MANAGED_PARAMS = [
28
        JWKParameter::PARAM_KEY_TYPE,
29
        JWKParameter::PARAM_KEY_VALUE,
30
    ];
31
32
    /**
33
     * Constructor.
34
     *
35
     * @param JWKParameter ...$params
36
     *
37
     * @throws \UnexpectedValueException If missing required parameter
38
     */
39 69
    public function __construct(JWKParameter ...$params)
40
    {
41 69
        parent::__construct(...$params);
42 69
        foreach (self::MANAGED_PARAMS as $name) {
43 69
            if (!$this->has($name)) {
44 1
                throw new \UnexpectedValueException(
45 69
                    "Missing '{$name}' parameter.");
46
            }
47
        }
48 68
        if (KeyTypeParameter::TYPE_OCT !== $this->keyTypeParameter()->value()) {
49 1
            throw new \UnexpectedValueException('Invalid key type.');
50
        }
51 67
    }
52
53
    /**
54
     * Initialize from a key string.
55
     *
56
     * @param string       $key       Symmetric key
57
     * @param JWKParameter ...$params Optional additional parameters
58
     *
59
     * @return self
60
     */
61 39
    public static function fromKey(string $key, JWKParameter ...$params): self
62
    {
63 39
        $params[] = new KeyTypeParameter(KeyTypeParameter::TYPE_OCT);
64 39
        $params[] = KeyValueParameter::fromString($key);
65 39
        return new self(...$params);
66
    }
67
68
    /**
69
     * Get the symmetric key.
70
     *
71
     * @return string
72
     */
73 39
    public function key(): string
74
    {
75 39
        return Base64::urlDecode($this->keyValueParameter()->value());
76
    }
77
}
78