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.

Jwt::verify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace Emarref\Jwt;
4
5
use Emarref\Jwt\Algorithm;
6
use Emarref\Jwt\Claim;
7
use Emarref\Jwt\Encoding;
8
use Emarref\Jwt\Encryption;
9
use Emarref\Jwt\Exception;
10
use Emarref\Jwt\HeaderParameter;
11
use Emarref\Jwt\Serialization;
12
use Emarref\Jwt\Signature;
13
use Emarref\Jwt\Verification;
14
15
class Jwt
16
{
17
    /**
18
     * @var Encoding\EncoderInterface
19
     */
20
    private $encoder;
21
22
    public function __construct()
23
    {
24
        $this->encoder = new Encoding\Base64();
25
    }
26
27
    /**
28
     * @param string $jwt
29
     * @return Token
30
     */
31
    public function deserialize($jwt)
32
    {
33
        $serialization = new Serialization\Compact(
34
            $this->encoder,
35
            new HeaderParameter\Factory(),
36
            new Claim\Factory()
37
        );
38
39
        return $serialization->deserialize($jwt);
40
    }
41
42
    /**
43
     * @param Token                          $token
44
     * @param Encryption\EncryptionInterface $encryption
45
     * @return string
46
     */
47
    public function serialize(Token $token, Encryption\EncryptionInterface $encryption)
48
    {
49
        $this->sign($token, $encryption);
50
51
        $serialization = new Serialization\Compact(
52
            $this->encoder,
53
            new HeaderParameter\Factory(),
54
            new Claim\Factory()
55
        );
56
57
        return $serialization->serialize($token);
58
    }
59
60
    /**
61
     * @param Token                          $token
62
     * @param Encryption\EncryptionInterface $encryption
63
     */
64
    public function sign(Token $token, Encryption\EncryptionInterface $encryption)
65
    {
66
        $signer = new Signature\Jws($encryption, $this->encoder);
67
68
        $signer->sign($token);
69
    }
70
71
    /**
72
     * @param Verification\Context $context
73
     * @return Verification\VerifierInterface[]
74
     */
75
    protected function getVerifiers(Verification\Context $context)
76
    {
77
        return [
78
            new Verification\EncryptionVerifier($context->getEncryption(), $this->encoder),
79
            new Verification\AudienceVerifier($context->getAudience()),
80
            new Verification\ExpirationVerifier(),
81
            new Verification\IssuerVerifier($context->getIssuer()),
82
            new Verification\SubjectVerifier($context->getSubject()),
83
            new Verification\NotBeforeVerifier(),
84
        ];
85
    }
86
87
    /**
88
     * @param Token                $token
89
     * @param Verification\Context $context
90
     * @return bool
91
     */
92
    public function verify(Token $token, Verification\Context $context)
93
    {
94
        foreach ($this->getVerifiers($context) as $verifier) {
95
            $verifier->verify($token);
96
        }
97
98
        return true;
99
    }
100
}
101