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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 49
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A algoByHeader() 0 7 2
A algoByName() 0 8 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