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 ( 5e3b1d...3195ef )
by Joni
03:54
created

hasX509CertificateSHA256ThumbprintParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace JWX\JWK;
4
5
use JWX\JWK\Parameter\AlgorithmParameter;
6
use JWX\JWK\Parameter\CurveParameter;
7
use JWX\JWK\Parameter\ECCPrivateKeyParameter;
8
use JWX\JWK\Parameter\ExponentParameter;
9
use JWX\JWK\Parameter\FirstCRTCoefficientParameter;
10
use JWX\JWK\Parameter\FirstFactorCRTExponentParameter;
11
use JWX\JWK\Parameter\FirstPrimeFactorParameter;
12
use JWX\JWK\Parameter\JWKParameter;
13
use JWX\JWK\Parameter\KeyIDParameter;
14
use JWX\JWK\Parameter\KeyOperationsParameter;
15
use JWX\JWK\Parameter\KeyTypeParameter;
16
use JWX\JWK\Parameter\KeyValueParameter;
17
use JWX\JWK\Parameter\ModulusParameter;
18
use JWX\JWK\Parameter\OtherPrimesInfoParameter;
19
use JWX\JWK\Parameter\PrivateExponentParameter;
20
use JWX\JWK\Parameter\PublicKeyUseParameter;
21
use JWX\JWK\Parameter\SecondFactorCRTExponentParameter;
22
use JWX\JWK\Parameter\SecondPrimeFactorParameter;
23
use JWX\JWK\Parameter\X509CertificateChainParameter;
24
use JWX\JWK\Parameter\X509CertificateSHA1ThumbprintParameter;
25
use JWX\JWK\Parameter\X509CertificateSHA256ThumbprintParameter;
26
use JWX\JWK\Parameter\X509URLParameter;
27
use JWX\JWK\Parameter\XCoordinateParameter;
28
use JWX\JWK\Parameter\YCoordinateParameter;
29
30
31
/**
32
 * Trait for JWK to provide parameter accessor methods for typed return values.
33
 */
34
trait TypedJWK
35
{
36
	/**
37
	 * Whether parameters are present.
38
	 *
39
	 * @param string ...$names Parameter names
40
	 * @return bool
41
	 */
42
	abstract public function has(...$names);
43
	
44
	/**
45
	 * Get a parameter.
46
	 *
47
	 * @param string $name Parameter name
48
	 * @return JWKParameter
49
	 */
50
	abstract public function get($name);
51
	
52
	/**
53
	 * Check whether the algorithm parameter is present.
54
	 *
55
	 * @return bool
56
	 */
57 61
	public function hasAlgorithmParameter() {
58 61
		return $this->has(JWKParameter::P_ALG);
59
	}
60
	
61
	/**
62
	 * Get the algorithm parameter.
63
	 *
64
	 * @throws \UnexpectedValueException If the parameter has a wrong class
65
	 * @throws \LogicException If the parameter is not present
66
	 * @return AlgorithmParameter
67
	 */
68 20
	public function algorithmParameter() {
69 20
		return self::_checkType($this->get(JWKParameter::P_ALG), 
70 20
			AlgorithmParameter::class);
71
	}
72
	
73
	/**
74
	 * Check whether the curve parameter is present.
75
	 *
76
	 * @return bool
77
	 */
78 1
	public function hasCurveParameter() {
79 1
		return $this->has(JWKParameter::P_CRV);
80
	}
81
	
82
	/**
83
	 * Get the curve parameter.
84
	 *
85
	 * @throws \UnexpectedValueException If the parameter has a wrong class
86
	 * @throws \LogicException If the parameter is not present
87
	 * @return CurveParameter
88
	 */
89 20
	public function curveParameter() {
90 20
		return self::_checkType($this->get(JWKParameter::P_CRV), 
91 20
			CurveParameter::class);
92
	}
93
	
94
	/**
95
	 * Check whether the ECC private key parameter is present.
96
	 *
97
	 * @return bool
98
	 */
99 1
	public function hasECCPrivateKeyParameter() {
100 1
		return $this->has(JWKParameter::P_ECC_D);
101
	}
102
	
103
	/**
104
	 * Get the ECC private key parameter.
105
	 *
106
	 * @throws \UnexpectedValueException If the parameter has a wrong class
107
	 * @throws \LogicException If the parameter is not present
108
	 * @return ECCPrivateKeyParameter
109
	 */
110 6
	public function ECCPrivateKeyParameter() {
111 6
		return self::_checkType($this->get(JWKParameter::P_ECC_D), 
112 6
			ECCPrivateKeyParameter::class);
113
	}
114
	
115
	/**
116
	 * Check whether the exponent parameter is present.
117
	 *
118
	 * @return bool
119
	 */
120 1
	public function hasExponentParameter() {
121 1
		return $this->has(JWKParameter::P_E);
122
	}
123
	
124
	/**
125
	 * Get the exponent parameter.
126
	 *
127
	 * @throws \UnexpectedValueException If the parameter has a wrong class
128
	 * @throws \LogicException If the parameter is not present
129
	 * @return ExponentParameter
130
	 */
131 41
	public function exponentParameter() {
132 41
		return self::_checkType($this->get(JWKParameter::P_E), 
133 41
			ExponentParameter::class);
134
	}
135
	
136
	/**
137
	 * Check whether the first CRT coefficient parameter is present.
138
	 *
139
	 * @return bool
140
	 */
141 1
	public function hasFirstCRTCoefficientParameter() {
142 1
		return $this->has(JWKParameter::P_QI);
143
	}
144
	
145
	/**
146
	 * Get the first CRT coefficient parameter.
147
	 *
148
	 * @throws \UnexpectedValueException If the parameter has a wrong class
149
	 * @throws \LogicException If the parameter is not present
150
	 * @return FirstCRTCoefficientParameter
151
	 */
152 17
	public function firstCRTCoefficientParameter() {
153 17
		return self::_checkType($this->get(JWKParameter::P_QI), 
154 17
			FirstCRTCoefficientParameter::class);
155
	}
156
	
157
	/**
158
	 * Check whether the first factor CRT exponent parameter is present.
159
	 *
160
	 * @return bool
161
	 */
162 1
	public function hasFirstFactorCRTExponentParameter() {
163 1
		return $this->has(JWKParameter::P_DP);
164
	}
165
	
166
	/**
167
	 * Get the first factor CRT exponent parameter.
168
	 *
169
	 * @throws \UnexpectedValueException If the parameter has a wrong class
170
	 * @throws \LogicException If the parameter is not present
171
	 * @return FirstFactorCRTExponentParameter
172
	 */
173 17
	public function firstFactorCRTExponentParameter() {
174 17
		return self::_checkType($this->get(JWKParameter::P_DP), 
175 17
			FirstFactorCRTExponentParameter::class);
176
	}
177
	
178
	/**
179
	 * Check whether the first prime factor parameter is present.
180
	 *
181
	 * @return bool
182
	 */
183 1
	public function hasFirstPrimeFactorParameter() {
184 1
		return $this->has(JWKParameter::P_P);
185
	}
186
	
187
	/**
188
	 * Get the first prime factor parameter.
189
	 *
190
	 * @throws \UnexpectedValueException If the parameter has a wrong class
191
	 * @throws \LogicException If the parameter is not present
192
	 * @return FirstPrimeFactorParameter
193
	 */
194 17
	public function firstPrimeFactorParameter() {
195 17
		return self::_checkType($this->get(JWKParameter::P_P), 
196 17
			FirstPrimeFactorParameter::class);
197
	}
198
	
199
	/**
200
	 * Check whether the key ID parameter is present.
201
	 *
202
	 * @return bool
203
	 */
204 1
	public function hasKeyIDParameter() {
205 1
		return $this->has(JWKParameter::P_KID);
206
	}
207
	
208
	/**
209
	 * Get the key ID parameter.
210
	 *
211
	 * @throws \UnexpectedValueException If the parameter has a wrong class
212
	 * @throws \LogicException If the parameter is not present
213
	 * @return KeyIDParameter
214
	 */
215 1
	public function keyIDParameter() {
216 1
		return self::_checkType($this->get(JWKParameter::P_KID), 
217 1
			KeyIDParameter::class);
218
	}
219
	
220
	/**
221
	 * Check whether the key operations parameter is present.
222
	 *
223
	 * @return bool
224
	 */
225 1
	public function hasKeyOperationsParameter() {
226 1
		return $this->has(JWKParameter::P_KEY_OPS);
227
	}
228
	
229
	/**
230
	 * Get the key operations parameter.
231
	 *
232
	 * @throws \UnexpectedValueException If the parameter has a wrong class
233
	 * @throws \LogicException If the parameter is not present
234
	 * @return KeyOperationsParameter
235
	 */
236 1
	public function keyOperationsParameter() {
237 1
		return self::_checkType($this->get(JWKParameter::P_KEY_OPS), 
238 1
			KeyOperationsParameter::class);
239
	}
240
	
241
	/**
242
	 * Check whether the key type parameter is present.
243
	 *
244
	 * @return bool
245
	 */
246 1
	public function hasKeyTypeParameter() {
247 1
		return $this->has(JWKParameter::P_KTY);
248
	}
249
	
250
	/**
251
	 * Get the key type parameter.
252
	 *
253
	 * @throws \UnexpectedValueException If the parameter has a wrong class
254
	 * @throws \LogicException If the parameter is not present
255
	 * @return KeyTypeParameter
256
	 */
257 128
	public function keyTypeParameter() {
258 128
		return self::_checkType($this->get(JWKParameter::P_KTY), 
259 128
			KeyTypeParameter::class);
260
	}
261
	
262
	/**
263
	 * Check whether the key value parameter is present.
264
	 *
265
	 * @return bool
266
	 */
267 1
	public function hasKeyValueParameter() {
268 1
		return $this->has(JWKParameter::P_K);
269
	}
270
	
271
	/**
272
	 * Get the key value parameter.
273
	 *
274
	 * @throws \UnexpectedValueException If the parameter has a wrong class
275
	 * @throws \LogicException If the parameter is not present
276
	 * @return KeyValueParameter
277
	 */
278 40
	public function keyValueParameter() {
279 40
		return self::_checkType($this->get(JWKParameter::P_K), 
280 40
			KeyValueParameter::class);
281
	}
282
	
283
	/**
284
	 * Check whether the modulus parameter is present.
285
	 *
286
	 * @return bool
287
	 */
288 1
	public function hasModulusParameter() {
289 1
		return $this->has(JWKParameter::P_N);
290
	}
291
	
292
	/**
293
	 * Get the modulus parameter.
294
	 *
295
	 * @throws \UnexpectedValueException If the parameter has a wrong class
296
	 * @throws \LogicException If the parameter is not present
297
	 * @return ModulusParameter
298
	 */
299 41
	public function modulusParameter() {
300 41
		return self::_checkType($this->get(JWKParameter::P_N), 
301 41
			ModulusParameter::class);
302
	}
303
	
304
	/**
305
	 * Check whether the other primes info parameter is present.
306
	 *
307
	 * @return bool
308
	 */
309 1
	public function hasOtherPrimesInfoParameter() {
310 1
		return $this->has(JWKParameter::P_OTH);
311
	}
312
	
313
	/**
314
	 * Get the other primes info parameter.
315
	 *
316
	 * @throws \UnexpectedValueException If the parameter has a wrong class
317
	 * @throws \LogicException If the parameter is not present
318
	 * @return OtherPrimesInfoParameter
319
	 */
320 1
	public function otherPrimesInfoParameter() {
321 1
		return self::_checkType($this->get(JWKParameter::P_OTH), 
322 1
			OtherPrimesInfoParameter::class);
323
	}
324
	
325
	/**
326
	 * Check whether the private exponent parameter is present.
327
	 *
328
	 * @return bool
329
	 */
330 1
	public function hasPrivateExponentParameter() {
331 1
		return $this->has(JWKParameter::P_RSA_D);
332
	}
333
	
334
	/**
335
	 * Get the private exponent parameter.
336
	 *
337
	 * @throws \UnexpectedValueException If the parameter has a wrong class
338
	 * @throws \LogicException If the parameter is not present
339
	 * @return PrivateExponentParameter
340
	 */
341 17
	public function privateExponentParameter() {
342 17
		return self::_checkType($this->get(JWKParameter::P_RSA_D), 
343 17
			PrivateExponentParameter::class);
344
	}
345
	
346
	/**
347
	 * Check whether the public key use parameter is present.
348
	 *
349
	 * @return bool
350
	 */
351 1
	public function hasPublicKeyUseParameter() {
352 1
		return $this->has(JWKParameter::P_USE);
353
	}
354
	
355
	/**
356
	 * Get the public key use parameter.
357
	 *
358
	 * @throws \UnexpectedValueException If the parameter has a wrong class
359
	 * @throws \LogicException If the parameter is not present
360
	 * @return PublicKeyUseParameter
361
	 */
362 1
	public function publicKeyUseParameter() {
363 1
		return self::_checkType($this->get(JWKParameter::P_USE), 
364 1
			PublicKeyUseParameter::class);
365
	}
366
	
367
	/**
368
	 * Check whether the second factor CRT exponent parameter is present.
369
	 *
370
	 * @return bool
371
	 */
372 1
	public function hasSecondFactorCRTExponentParameter() {
373 1
		return $this->has(JWKParameter::P_DQ);
374
	}
375
	
376
	/**
377
	 * Get the second factor CRT exponent parameter.
378
	 *
379
	 * @throws \UnexpectedValueException If the parameter has a wrong class
380
	 * @throws \LogicException If the parameter is not present
381
	 * @return SecondFactorCRTExponentParameter
382
	 */
383 17
	public function secondFactorCRTExponentParameter() {
384 17
		return self::_checkType($this->get(JWKParameter::P_DQ), 
385 17
			SecondFactorCRTExponentParameter::class);
386
	}
387
	
388
	/**
389
	 * Check whether the second prime factor parameter is present.
390
	 *
391
	 * @return bool
392
	 */
393 1
	public function hasSecondPrimeFactorParameter() {
394 1
		return $this->has(JWKParameter::P_Q);
395
	}
396
	
397
	/**
398
	 * Get the second prime factor parameter.
399
	 *
400
	 * @throws \UnexpectedValueException If the parameter has a wrong class
401
	 * @throws \LogicException If the parameter is not present
402
	 * @return SecondPrimeFactorParameter
403
	 */
404 17
	public function secondPrimeFactorParameter() {
405 17
		return self::_checkType($this->get(JWKParameter::P_Q), 
406 17
			SecondPrimeFactorParameter::class);
407
	}
408
	
409
	/**
410
	 * Check whether the X.509 certificate chain parameter is present.
411
	 *
412
	 * @return bool
413
	 */
414 1
	public function hasX509CertificateChainParameter() {
415 1
		return $this->has(JWKParameter::P_X5C);
416
	}
417
	
418
	/**
419
	 * Get the X.509 certificate chain parameter.
420
	 *
421
	 * @throws \UnexpectedValueException If the parameter has a wrong class
422
	 * @throws \LogicException If the parameter is not present
423
	 * @return X509CertificateChainParameter
424
	 */
425 1
	public function X509CertificateChainParameter() {
426 1
		return self::_checkType($this->get(JWKParameter::P_X5C), 
427 1
			X509CertificateChainParameter::class);
428
	}
429
	
430
	/**
431
	 * Check whether the X.509 certificate SHA-1 thumbprint parameter is
432
	 * present.
433
	 *
434
	 * @return bool
435
	 */
436 1
	public function hasX509CertificateSHA1ThumbprintParameter() {
437 1
		return $this->has(JWKParameter::P_X5T);
438
	}
439
	
440
	/**
441
	 * Get the X.509 certificate SHA-1 thumbprint parameter.
442
	 *
443
	 * @throws \UnexpectedValueException If the parameter has a wrong class
444
	 * @throws \LogicException If the parameter is not present
445
	 * @return X509CertificateSHA1ThumbprintParameter
446
	 */
447 1
	public function X509CertificateSHA1ThumbprintParameter() {
448 1
		return self::_checkType($this->get(JWKParameter::P_X5T), 
449 1
			X509CertificateSHA1ThumbprintParameter::class);
450
	}
451
	
452
	/**
453
	 * Check whether the X.509 certificate SHA-256 thumbprint parameter is
454
	 * present.
455
	 *
456
	 * @return bool
457
	 */
458 1
	public function hasX509CertificateSHA256ThumbprintParameter() {
459 1
		return $this->has(JWKParameter::P_X5TS256);
460
	}
461
	
462
	/**
463
	 * Get the X.509 certificate SHA-256 thumbprint parameter.
464
	 *
465
	 * @throws \UnexpectedValueException If the parameter has a wrong class
466
	 * @throws \LogicException If the parameter is not present
467
	 * @return X509CertificateSHA256ThumbprintParameter
468
	 */
469 1
	public function X509CertificateSHA256ThumbprintParameter() {
470 1
		return self::_checkType($this->get(JWKParameter::P_X5TS256), 
471 1
			X509CertificateSHA256ThumbprintParameter::class);
472
	}
473
	
474
	/**
475
	 * Check whether the X.509 URL parameter is present.
476
	 *
477
	 * @return bool
478
	 */
479 1
	public function hasX509URLParameter() {
480 1
		return $this->has(JWKParameter::P_X5U);
481
	}
482
	
483
	/**
484
	 * Get the X.509 URL parameter.
485
	 *
486
	 * @throws \UnexpectedValueException If the parameter has a wrong class
487
	 * @throws \LogicException If the parameter is not present
488
	 * @return X509URLParameter
489
	 */
490 1
	public function X509URLParameter() {
491 1
		return self::_checkType($this->get(JWKParameter::P_X5U), 
492 1
			X509URLParameter::class);
493
	}
494
	
495
	/**
496
	 * Check whether the X coordinate parameter is present.
497
	 *
498
	 * @return bool
499
	 */
500 1
	public function hasXCoordinateParameter() {
501 1
		return $this->has(JWKParameter::P_X);
502
	}
503
	
504
	/**
505
	 * Get the X coordinate parameter.
506
	 *
507
	 * @throws \UnexpectedValueException If the parameter has a wrong class
508
	 * @throws \LogicException If the parameter is not present
509
	 * @return XCoordinateParameter
510
	 */
511 16
	public function XCoordinateParameter() {
512 16
		return self::_checkType($this->get(JWKParameter::P_X), 
513 16
			XCoordinateParameter::class);
514
	}
515
	
516
	/**
517
	 * Check whether the Y coordinate parameter is present.
518
	 *
519
	 * @return bool
520
	 */
521 1
	public function hasYCoordinateParameter() {
522 1
		return $this->has(JWKParameter::P_Y);
523
	}
524
	
525
	/**
526
	 * Get the Y coordinate parameter.
527
	 *
528
	 * @throws \UnexpectedValueException If the parameter has a wrong class
529
	 * @throws \LogicException If the parameter is not present
530
	 * @return YCoordinateParameter
531
	 */
532 16
	public function YCoordinateParameter() {
533 16
		return self::_checkType($this->get(JWKParameter::P_Y), 
534 16
			YCoordinateParameter::class);
535
	}
536
	
537
	/**
538
	 * Check that the parameter is an instance of the given class.
539
	 *
540
	 * @param JWKParameter $param Parameter
541
	 * @param string $cls Class name
542
	 * @throws \UnexpectedValueException
543
	 * @return JWKParameter
544
	 */
545 179 View Code Duplication
	private static function _checkType(JWKParameter $param, $cls) {
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...
546 179
		if (!$param instanceof $cls) {
547 1
			throw new \UnexpectedValueException(
548 1
				"$cls expected, got " . get_class($param));
549
		}
550 178
		return $param;
551
	}
552
}
553