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.
Completed
Push — master ( 70b15e...4c8633 )
by Joni
04:39
created

SignatureAlgorithm::withKeyID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace JWX\JWS;
4
5
use JWX\JWK\JWK;
6
use JWX\JWS\Algorithm\SignatureAlgorithmFactory;
7
use JWX\JWT\Header\Header;
8
use JWX\JWT\Header\HeaderParameters;
9
use JWX\JWT\Parameter\AlgorithmParameterValue;
10
use JWX\JWT\Parameter\KeyIDParameter;
11
12
13
/**
14
 * Base class for algorithms usable for signing and validating JWS's.
15
 */
16
abstract class SignatureAlgorithm implements 
17
	AlgorithmParameterValue, 
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 1 found
Loading history...
18
	HeaderParameters
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 1 found
Loading history...
19
{
20
	/**
21
	 * ID of the key used by the algorithm.
22
	 *
23
	 * If set, KeyID parameter shall be automatically inserted into JWS's
24
	 * header.
25
	 *
26
	 * @var string|null $_keyID
27
	 */
28
	protected $_keyID;
29
	
30
	/**
31
	 * Compute signature.
32
	 *
33
	 * @param string $data Data for which the signature is computed
34
	 * @return string
35
	 */
36
	abstract public function computeSignature($data);
37
	
38
	/**
39
	 * Validate signature.
40
	 *
41
	 * @param string $data Data to validate
42
	 * @param string $signature Signature to compare
43
	 * @return bool
44
	 */
45
	abstract public function validateSignature($data, $signature);
46
	
47
	/**
48
	 * Initialize signature algorithm from a JWK and a header.
49
	 *
50
	 * @param JWK $jwk JSON Web Key
51
	 * @param Header $header Header
52
	 * @return SignatureAlgorithm
53
	 */
54 5
	public static function fromJWK(JWK $jwk, Header $header) {
55 5
		$factory = new SignatureAlgorithmFactory($header);
56 5
		return $factory->algoByKey($jwk);
57
	}
58
	
59
	/**
60
	 * Get self with key ID.
61
	 *
62
	 * @param string|null $id Key ID or null to remove
63
	 * @return self
64
	 */
65 2
	public function withKeyID($id) {
66 2
		$obj = clone $this;
67 2
		$obj->_keyID = $id;
68 2
		return $obj;
69
	}
70
	
71
	/**
72
	 *
73
	 * @see \JWX\JWT\Header\HeaderParameters::headerParameters()
74
	 * @return JWTParameter[]
75
	 */
76 18 View Code Duplication
	public function headerParameters() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77 18
		$params = array();
78 18
		if (isset($this->_keyID)) {
79 2
			$params[] = new KeyIDParameter($this->_keyID);
80 2
		}
81 18
		return $params;
82
	}
83
}
84