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 ( 59f4b4...e271c1 )
by Joni
03:51
created

CompressionFactory::algoByName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 6
cts 6
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
    const MAP_ALGO_TO_CLASS = [
24
        JWA::ALGO_DEFLATE => DeflateAlgorithm::class,
25
    ];
26
27
    /**
28
     * Get the compression algorithm by name.
29
     *
30
     * @param string $name
31
     *
32
     * @throws \UnexpectedValueException If algorithm is not supported
33
     *
34
     * @return CompressionAlgorithm
35
     */
36 7
    public static function algoByName(string $name): CompressionAlgorithm
37
    {
38 7
        if (!array_key_exists($name, self::MAP_ALGO_TO_CLASS)) {
39 1
            throw new \UnexpectedValueException(
40 1
                "No compression algorithm '{$name}'.");
41
        }
42 6
        $cls = self::MAP_ALGO_TO_CLASS[$name];
43 6
        return new $cls();
44
    }
45
46
    /**
47
     * Get the compression algorithm as specified in the given header.
48
     *
49
     * @param Header $header Header
50
     *
51
     * @throws \UnexpectedValueException If compression algorithm parameter is
52
     *                                   not present or algorithm is not supported
53
     *
54
     * @return CompressionAlgorithm
55
     */
56 4
    public static function algoByHeader(Header $header): CompressionAlgorithm
57
    {
58 4
        if (!$header->hasCompressionAlgorithm()) {
59 1
            throw new \UnexpectedValueException(
60 1
                'No compression algorithm parameter.');
61
        }
62 3
        return self::algoByName($header->compressionAlgorithm()->value());
63
    }
64
}
65