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

CompressionFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 17.02 %

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 47
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\CompressionAlgorithm;
4
5
use JWX\JWA\JWA;
6
use JWX\JWE\CompressionAlgorithm;
7
use JWX\JWT\Header\Header;
8
9
10
/**
11
 * Factory class to construct compression algorithm instances.
12
 */
13
abstract class CompressionFactory
14
{
15
	/**
16
	 * Mapping from algorithm name to class name.
17
	 *
18
	 * @internal
19
	 *
20
	 * @var array
21
	 */
22
	const MAP_ALGO_TO_CLASS = array(
23
		/* @formatter:off */
24
		JWA::ALGO_DEFLATE => DeflateAlgorithm::class
25
		/* @formatter:on */
26
	);
27
	
28
	/**
29
	 * Get the compression algorithm by name.
30
	 *
31
	 * @param string $name
32
	 * @throws \UnexpectedValueException If algorithm is not supported
33
	 * @return CompressionAlgorithm
34
	 */
35 7 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...
36 7
		if (!array_key_exists($name, self::MAP_ALGO_TO_CLASS)) {
37 1
			throw new \UnexpectedValueException(
38 1
				"No compression algorithm '$name'.");
39
		}
40 6
		$cls = self::MAP_ALGO_TO_CLASS[$name];
41 6
		return new $cls();
42
	}
43
	
44
	/**
45
	 * Get the compression algorithm as specified in the given header.
46
	 *
47
	 * @param Header $header Header
48
	 * @throws \UnexpectedValueException If compression algorithm parameter is
49
	 *         not present or algorithm is not supported
50
	 * @return CompressionAlgorithm
51
	 */
52 4
	public static function algoByHeader(Header $header) {
53 4
		if (!$header->hasCompressionAlgorithm()) {
54 1
			throw new \UnexpectedValueException(
55 1
				"No compression algorithm parameter.");
56
		}
57 3
		return self::algoByName($header->compressionAlgorithm()->value());
58
	}
59
}
60