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.

Hmac::ensureSupport()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace Emarref\Jwt\Algorithm;
4
5
abstract class Hmac implements SymmetricInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    private $secret;
11
12
    /**
13
     * @param string $secret
14
     */
15
    public function __construct($secret)
16
    {
17
        $this->secret = $secret;
18
19
        $this->ensureSupport();
20
    }
21
22
    /**
23
     * @throws \RuntimeException
24
     */
25
    private function ensureSupport()
26
    {
27
        $supportedAlgorithms = $this->getSupportedAlgorithms();
28
29
        if (!in_array($this->getAlgorithm(), $supportedAlgorithms)) {
30
            throw new \RuntimeException(sprintf(
31
                'Encryption algorithm "%s" is not supported on this system.',
32
                $this->getAlgorithm()
33
            ));
34
        }
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    protected function getSupportedAlgorithms()
41
    {
42
        return hash_algos();
43
    }
44
45
    /**
46
     * @param string $value
47
     * @return string
48
     */
49
    public function compute($value)
50
    {
51
        return hash_hmac($this->getAlgorithm(), $value, $this->secret, true);
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    abstract protected function getAlgorithm();
58
}
59