Total Complexity | 4 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
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 |
|
57 | } |
||
58 | } |
||
59 |