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 ( e7c776...4b2105 )
by Joni
05:35
created

EncryptionAlgorithmFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A algoByName() 8 8 2
A algoByHeader() 0 7 2

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\JWE\EncryptionAlgorithm;
4
5
use JWX\JWA\JWA;
6
use JWX\JWE\ContentEncryptionAlgorithm;
7
use JWX\JWE\EncryptionAlgorithm\A128CBCHS256Algorithm;
8
use JWX\JWE\EncryptionAlgorithm\A128GCMAlgorithm;
9
use JWX\JWE\EncryptionAlgorithm\A192CBCHS384Algorithm;
10
use JWX\JWE\EncryptionAlgorithm\A192GCMAlgorithm;
11
use JWX\JWE\EncryptionAlgorithm\A256CBCHS512Algorithm;
12
use JWX\JWE\EncryptionAlgorithm\A256GCMAlgorithm;
13
use JWX\JWT\Header\Header;
14
15
16
/**
17
 * Factory class to construct content encryption algorithm instances.
18
 */
19
abstract class EncryptionAlgorithmFactory
20
{
21
	/**
22
	 * Mapping from algorithm name to class name.
23
	 *
24
	 * @internal
25
	 *
26
	 * @var array
27
	 */
28
	const MAP_ALGO_TO_CLASS = array(
29
		/* @formatter:off */
30
		JWA::ALGO_A128CBC_HS256 => A128CBCHS256Algorithm::class,
31
		JWA::ALGO_A192CBC_HS384 => A192CBCHS384Algorithm::class,
32
		JWA::ALGO_A256CBC_HS512 => A256CBCHS512Algorithm::class,
33
		JWA::ALGO_A128GCM => A128GCMAlgorithm::class,
34
		JWA::ALGO_A192GCM => A192GCMAlgorithm::class,
35
		JWA::ALGO_A256GCM => A256GCMAlgorithm::class
36
		/* @formatter:on */
37
	);
38
	
39
	/**
40
	 * Get the content encryption algorithm by algorithm name.
41
	 *
42
	 * @param string $name Algorithm name
43
	 * @throws \UnexpectedValueException If algorithm is not supported.
44
	 * @return ContentEncryptionAlgorithm
45
	 */
46 18 View Code Duplication
	public static function algoByName($name) {
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...
47 18
		if (!array_key_exists($name, self::MAP_ALGO_TO_CLASS)) {
48 1
			throw new \UnexpectedValueException(
49 1
				"No content encryption algorithm '$name'.");
50
		}
51 17
		$cls = self::MAP_ALGO_TO_CLASS[$name];
52 17
		return new $cls();
53
	}
54
	
55
	/**
56
	 * Get the content encryption algorithm as specified in the given header.
57
	 *
58
	 * @param Header $header Header
59
	 * @throws \UnexpectedValueException If content encryption algorithm
60
	 *         parameter is not present or algorithm is not supported.
61
	 * @return ContentEncryptionAlgorithm
62
	 */
63 3
	public static function algoByHeader(Header $header) {
64 3
		if (!$header->hasEncryptionAlgorithm()) {
65 1
			throw new \UnexpectedValueException(
66 1
				"No encryption algorithm parameter.");
67
		}
68 2
		return self::algoByName($header->encryptionAlgorithm()->value());
69
	}
70
}
71