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.

TypedJWK   B
last analyzed

Complexity

Total Complexity 48

Size/Duplication

Total Lines 493
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 48
eloc 74
dl 0
loc 493
ccs 120
cts 120
cp 1
rs 8.5599
c 0
b 0
f 0

47 Methods

Rating   Name   Duplication   Size   Complexity  
A otherPrimesInfoParameter() 0 4 1
A curveParameter() 0 4 1
A publicKeyUseParameter() 0 4 1
A secondPrimeFactorParameter() 0 4 1
A hasPrivateExponentParameter() 0 3 1
A hasAlgorithmParameter() 0 3 1
A modulusParameter() 0 4 1
A hasFirstPrimeFactorParameter() 0 3 1
A hasX509CertificateChainParameter() 0 3 1
A hasExponentParameter() 0 3 1
A keyIDParameter() 0 4 1
A XCoordinateParameter() 0 4 1
A hasX509URLParameter() 0 3 1
A hasCurveParameter() 0 3 1
A hasOtherPrimesInfoParameter() 0 3 1
A privateExponentParameter() 0 4 1
A hasSecondPrimeFactorParameter() 0 3 1
A X509CertificateChainParameter() 0 4 1
A X509CertificateSHA1ThumbprintParameter() 0 4 1
A hasFirstCRTCoefficientParameter() 0 3 1
A hasYCoordinateParameter() 0 3 1
A hasKeyValueParameter() 0 3 1
A algorithmParameter() 0 4 1
A hasKeyIDParameter() 0 3 1
A hasSecondFactorCRTExponentParameter() 0 3 1
A ECCPrivateKeyParameter() 0 4 1
A X509URLParameter() 0 4 1
A hasFirstFactorCRTExponentParameter() 0 3 1
A hasPublicKeyUseParameter() 0 3 1
A exponentParameter() 0 4 1
A firstPrimeFactorParameter() 0 4 1
A hasKeyTypeParameter() 0 3 1
A secondFactorCRTExponentParameter() 0 4 1
A firstFactorCRTExponentParameter() 0 4 1
A keyTypeParameter() 0 4 1
A _checkType() 0 7 2
A hasX509CertificateSHA1ThumbprintParameter() 0 3 1
A keyOperationsParameter() 0 4 1
A hasECCPrivateKeyParameter() 0 3 1
A hasXCoordinateParameter() 0 3 1
A YCoordinateParameter() 0 4 1
A X509CertificateSHA256ThumbprintParameter() 0 4 1
A hasModulusParameter() 0 3 1
A keyValueParameter() 0 4 1
A hasX509CertificateSHA256ThumbprintParameter() 0 3 1
A firstCRTCoefficientParameter() 0 4 1
A hasKeyOperationsParameter() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like TypedJWK often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TypedJWK, and based on these observations, apply Extract Interface, too.

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