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.

TypedClaims::hasIssuer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\JWX\JWT\Claim;
6
7
/**
8
 * Trait for Claims to provide claim accessor methods for typed return values.
9
 */
10
trait TypedClaims
11
{
12
    /**
13
     * Check whether the claim is present.
14
     *
15
     * @param string $name Claim name
16
     */
17
    abstract public function has(string $name): bool;
18
19
    /**
20
     * Get the claim by name.
21
     *
22
     * @param string $name Claim name
23
     */
24
    abstract public function get(string $name): Claim;
25
26
    /**
27
     * Check whether the issuer claim is present.
28
     */
29 1
    public function hasIssuer(): bool
30
    {
31 1
        return $this->has(RegisteredClaim::NAME_ISSUER);
32
    }
33
34
    /**
35
     * Get the issuer claim.
36
     */
37 2
    public function issuer(): IssuerClaim
38
    {
39 2
        return self::_checkType($this->get(RegisteredClaim::NAME_ISSUER),
40 2
            IssuerClaim::class);
41
    }
42
43
    /**
44
     * Check whether the subject claim is present.
45
     */
46 1
    public function hasSubject(): bool
47
    {
48 1
        return $this->has(RegisteredClaim::NAME_SUBJECT);
49
    }
50
51
    /**
52
     * Get the subject claim.
53
     */
54 1
    public function subject(): SubjectClaim
55
    {
56 1
        return self::_checkType($this->get(RegisteredClaim::NAME_SUBJECT),
57 1
            SubjectClaim::class);
58
    }
59
60
    /**
61
     * Check whether the audience claim is present.
62
     */
63 1
    public function hasAudience(): bool
64
    {
65 1
        return $this->has(RegisteredClaim::NAME_AUDIENCE);
66
    }
67
68
    /**
69
     * Get the audience claim.
70
     */
71 1
    public function audience(): AudienceClaim
72
    {
73 1
        return self::_checkType($this->get(RegisteredClaim::NAME_AUDIENCE),
74 1
            AudienceClaim::class);
75
    }
76
77
    /**
78
     * Check whether the expiration time claim is present.
79
     */
80 1
    public function hasExpirationTime(): bool
81
    {
82 1
        return $this->has(RegisteredClaim::NAME_EXPIRATION_TIME);
83
    }
84
85
    /**
86
     * Get the expiration time claim.
87
     */
88 1
    public function expirationTime(): ExpirationTimeClaim
89
    {
90 1
        return self::_checkType(
91 1
            $this->get(RegisteredClaim::NAME_EXPIRATION_TIME),
92 1
            ExpirationTimeClaim::class);
93
    }
94
95
    /**
96
     * Check whether the not before claim is present.
97
     */
98 1
    public function hasNotBefore(): bool
99
    {
100 1
        return $this->has(RegisteredClaim::NAME_NOT_BEFORE);
101
    }
102
103
    /**
104
     * Get the not before claim.
105
     */
106 1
    public function notBefore(): NotBeforeClaim
107
    {
108 1
        return self::_checkType($this->get(RegisteredClaim::NAME_NOT_BEFORE),
109 1
            NotBeforeClaim::class);
110
    }
111
112
    /**
113
     * Check whether the issued at claim is present.
114
     */
115 1
    public function hasIssuedAt(): bool
116
    {
117 1
        return $this->has(RegisteredClaim::NAME_ISSUED_AT);
118
    }
119
120
    /**
121
     * Get the issued at claim.
122
     */
123 1
    public function issuedAt(): IssuedAtClaim
124
    {
125 1
        return self::_checkType($this->get(RegisteredClaim::NAME_ISSUED_AT),
126 1
            IssuedAtClaim::class);
127
    }
128
129
    /**
130
     * Check whether the JWT ID claim is present.
131
     */
132 1
    public function hasJWTID(): bool
133
    {
134 1
        return $this->has(RegisteredClaim::NAME_JWT_ID);
135
    }
136
137
    /**
138
     * Get the JWT ID claim.
139
     */
140 1
    public function JWTID(): JWTIDClaim
141
    {
142 1
        return self::_checkType($this->get(RegisteredClaim::NAME_JWT_ID),
143 1
            JWTIDClaim::class);
144
    }
145
146
    /**
147
     * Check that the claim is an instance of the given class.
148
     *
149
     * @param Claim  $claim Claim object
150
     * @param string $cls   Class name
151
     *
152
     * @throws \UnexpectedValueException
153
     */
154 8
    private static function _checkType(Claim $claim, string $cls): Claim
155
    {
156 8
        if (!$claim instanceof $cls) {
157 1
            throw new \UnexpectedValueException(
158 1
                "{$cls} expected, got " . get_class($claim));
159
        }
160 7
        return $claim;
161
    }
162
}
163