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::algoByHeader()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
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