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 ( 584c7d...11b52a )
by Joni
04:10
created

JWTParameter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 116
Duplicated Lines 6.03 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 1
dl 7
loc 116
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromNameAndValue() 7 7 2
A fromJSONValue() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace JWX\JWT\Parameter;
4
5
use JWX\Parameter\Parameter;
6
7
8
/**
9
 * Represents a header parameter.
10
 *
11
 * @link https://tools.ietf.org/html/rfc7519#section-5
12
 * @link
13
 *       http://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-header-parameters
14
 */
15
class JWTParameter extends Parameter
16
{
17
	// registered parameter names
18
	const PARAM_ALGORITHM = "alg";
19
	const PARAM_JWK_SET_URL = "jku";
20
	const PARAM_JSON_WEB_KEY = "jwk";
21
	const PARAM_KEY_ID = "kid";
22
	const PARAM_X509_URL = "x5u";
23
	const PARAM_X509_CERTIFICATE_CHAIN = "x5c";
24
	const PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT = "x5t";
25
	const PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT = "x5t#S256";
26
	const PARAM_TYPE = "typ";
27
	const PARAM_CONTENT_TYPE = "cty";
28
	const PARAM_CRITICAL = "crit";
29
	const PARAM_ENCRYPTION_ALGORITHM = "enc";
30
	const PARAM_COMPRESSION_ALGORITHM = "zip";
31
	const PARAM_EPHEMERAL_PUBLIC_KEY = "epk";
32
	const PARAM_AGREEMENT_PARTYUINFO = "apu";
33
	const PARAM_AGREEMENT_PARTYVINFO = "apv";
34
	const PARAM_INITIALIZATION_VECTOR = "iv";
35
	const PARAM_AUTHENTICATION_TAG = "tag";
36
	const PARAM_PBES2_SALT_INPUT = "p2s";
37
	const PARAM_PBES2_COUNT = "p2c";
38
	const PARAM_BASE64URL_ENCODE_PAYLOAD = "b64";
39
	
40
	// shorthand aliases for parameter names
41
	const P_ALG = self::PARAM_ALGORITHM;
42
	const P_JKU = self::PARAM_JWK_SET_URL;
43
	const P_JWK = self::PARAM_JSON_WEB_KEY;
44
	const P_KID = self::PARAM_KEY_ID;
45
	const P_X5U = self::PARAM_X509_URL;
46
	const P_X5C = self::PARAM_X509_CERTIFICATE_CHAIN;
47
	const P_X5T = self::PARAM_X509_CERTIFICATE_SHA1_THUMBPRINT;
48
	const P_X5TS256 = self::PARAM_X509_CERTIFICATE_SHA256_THUMBPRINT;
49
	const P_TYP = self::PARAM_TYPE;
50
	const P_CTY = self::PARAM_CONTENT_TYPE;
51
	const P_CRIT = self::PARAM_CRITICAL;
52
	const P_ENC = self::PARAM_ENCRYPTION_ALGORITHM;
53
	const P_ZIP = self::PARAM_COMPRESSION_ALGORITHM;
54
	const P_EPK = self::PARAM_EPHEMERAL_PUBLIC_KEY;
55
	const P_APU = self::PARAM_AGREEMENT_PARTYUINFO;
56
	const P_APV = self::PARAM_AGREEMENT_PARTYVINFO;
57
	const P_IV = self::PARAM_INITIALIZATION_VECTOR;
58
	const P_TAG = self::PARAM_AUTHENTICATION_TAG;
59
	const P_P2S = self::PARAM_PBES2_SALT_INPUT;
60
	const P_P2C = self::PARAM_PBES2_COUNT;
61
	const P_B64 = self::PARAM_BASE64URL_ENCODE_PAYLOAD;
62
	
63
	/**
64
	 * Mapping from registered JWT parameter name to class name.
65
	 *
66
	 * @internal
67
	 *
68
	 * @var array
69
	 */
70
	const MAP_NAME_TO_CLASS = array(
71
		/* @formatter:off */
72
		self::P_ALG => AlgorithmParameter::class,
73
		self::P_JKU => JWKSetURLParameter::class,
74
		self::P_JWK => JSONWebKeyParameter::class,
75
		self::P_KID => KeyIDParameter::class,
76
		self::P_X5U => X509URLParameter::class,
77
		self::P_X5C => X509CertificateChainParameter::class,
78
		self::P_X5T => X509CertificateSHA1ThumbprintParameter::class,
79
		self::P_X5TS256 => X509CertificateSHA256ThumbprintParameter::class,
80
		self::P_TYP => TypeParameter::class,
81
		self::P_CTY => ContentTypeParameter::class,
82
		self::P_CRIT => CriticalParameter::class,
83
		self::P_ENC => EncryptionAlgorithmParameter::class,
84
		self::P_ZIP => CompressionAlgorithmParameter::class,
85
		self::P_IV => InitializationVectorParameter::class,
86
		self::P_TAG => AuthenticationTagParameter::class,
87
		self::P_P2S => PBES2SaltInputParameter::class,
88
		self::P_P2C => PBES2CountParameter::class,
89
		self::P_B64 => B64PayloadParameter::class
90
		/* @formatter:on */
91
	);
92
	
93
	/**
94
	 * Constructor.
95
	 *
96
	 * @param string $name Parameter name
97
	 * @param mixed $value Parameter value
98
	 */
99 168
	public function __construct($name, $value) {
100 168
		$this->_name = $name;
101 168
		$this->_value = $value;
102 168
	}
103
	
104
	/**
105
	 * Initialize from a name and a value.
106
	 *
107
	 * Returns a parameter specific object if one is implemented.
108
	 *
109
	 * @param string $name Parameter name
110
	 * @param mixed $value Parameter value
111
	 * @return self
112
	 */
113 53 View Code Duplication
	public static function fromNameAndValue($name, $value) {
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...
114 53
		if (array_key_exists($name, self::MAP_NAME_TO_CLASS)) {
115 52
			$cls = self::MAP_NAME_TO_CLASS[$name];
116 52
			return $cls::fromJSONValue($value);
117
		}
118 1
		return new self($name, $value);
119
	}
120
	
121
	/**
122
	 * Initialize a concrete JWT parameter instance from a JSON value.
123
	 *
124
	 * @param mixed $value
125
	 * @return self
126
	 */
127 52
	public static function fromJSONValue($value) {
128 52
		return new static($value);
0 ignored issues
show
Bug introduced by
The call to JWTParameter::__construct() misses a required argument $value.

This check looks for function calls that miss required arguments.

Loading history...
129
	}
130
}
131