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.

CompressionFactory::algoByHeader()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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