Completed
Push — master ( 02cfb9...95b30c )
by Artem
06:06
created

JwtAlgorithm::assertValidAlgorithm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/*
3
 * This file is part of the FreshCentrifugoBundle.
4
 *
5
 * (c) Artem Henvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Fresh\CentrifugoBundle\Token;
14
15
use Fresh\CentrifugoBundle\Exception\InvalidArgumentException;
16
17
/**
18
 * JwtAlgorithm.
19
 *
20
 * @author Artem Henvald <[email protected]>
21
 */
22
final class JwtAlgorithm
23
{
24
    public const HS256 = 'HS256';
25
26
    public const RSA = 'RSA';
27
28
    /**
29
     * @param string $algorithm
30
     *
31
     * @throws InvalidArgumentException
32
     */
33
    public static function assertValidAlgorithm(string $algorithm): void
34
    {
35
        $reflectionClass = new \ReflectionClass(self::class);
36
        $availableAlgorithms = $reflectionClass->getConstants();
37
38
        if (!\in_array($algorithm, $availableAlgorithms, true)) {
39
            throw new InvalidArgumentException(\sprintf('Unsupported JWT algorithm: %s', $algorithm));
40
        }
41
    }
42
}
43