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

SignatureAlgorithm::headerParameters()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\JWX\JWS;
6
7
use Sop\JWX\JWK\JWK;
8
use Sop\JWX\JWS\Algorithm\SignatureAlgorithmFactory;
9
use Sop\JWX\JWT\Header\Header;
10
use Sop\JWX\JWT\Header\HeaderParameters;
11
use Sop\JWX\JWT\Parameter\AlgorithmParameterValue;
12
use Sop\JWX\JWT\Parameter\KeyIDParameter;
13
14
/**
15
 * Base class for algorithms usable for signing and validating JWS's.
16
 */
17
abstract class SignatureAlgorithm implements AlgorithmParameterValue, HeaderParameters
18
{
19
    /**
20
     * ID of the key used by the algorithm.
21
     *
22
     * If set, KeyID parameter shall be automatically inserted into JWS's
23
     * header.
24
     *
25
     * @var null|string
26
     */
27
    protected $_keyID;
28
29
    /**
30
     * Compute signature.
31
     *
32
     * @param string $data Data for which the signature is computed
33
     *
34
     * @return string
35
     */
36
    abstract public function computeSignature(string $data): string;
37
38
    /**
39
     * Validate signature.
40
     *
41
     * @param string $data      Data to validate
42
     * @param string $signature Signature to compare
43
     *
44
     * @return bool
45
     */
46
    abstract public function validateSignature(string $data, string $signature): bool;
47
48
    /**
49
     * Initialize signature algorithm from a JWK and a header.
50
     *
51
     * @param JWK    $jwk    JSON Web Key
52
     * @param Header $header Header
53
     *
54
     * @return SignatureAlgorithm
55
     */
56 5
    public static function fromJWK(JWK $jwk, Header $header): SignatureAlgorithm
57
    {
58 5
        $factory = new SignatureAlgorithmFactory($header);
59 5
        return $factory->algoByKey($jwk);
60
    }
61
62
    /**
63
     * Get self with key ID.
64
     *
65
     * @param null|string $id Key ID or null to remove
66
     *
67
     * @return self
68
     */
69 2
    public function withKeyID(?string $id): self
70
    {
71 2
        $obj = clone $this;
72 2
        $obj->_keyID = $id;
73 2
        return $obj;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 18
    public function headerParameters(): array
80
    {
81 18
        $params = [];
82 18
        if (isset($this->_keyID)) {
83 2
            $params[] = new KeyIDParameter($this->_keyID);
1 ignored issue
show
Bug introduced by
It seems like $this->_keyID can also be of type null; however, parameter $id of Sop\JWX\JWT\Parameter\Ke...arameter::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

83
            $params[] = new KeyIDParameter(/** @scrutinizer ignore-type */ $this->_keyID);
Loading history...
84
        }
85 18
        return $params;
86
    }
87
}
88