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.

ClaimBuilder   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 104
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 2

9 Methods

Rating   Name   Duplication   Size   Complexity  
A issuedBy() 0 4 1
A relatedTo() 0 4 1
A intendedFor() 0 4 1
A expireAt() 0 4 1
A canOnlyBeUsedAfter() 0 4 1
A issuedAt() 0 4 1
A identifiedBy() 0 4 1
B getValue() 0 19 7
A collectClaim() 0 10 2
1
<?php
2
3
namespace Gandung\JWT\Token;
4
5
use Gandung\JWT\Exception\ClaimTokenMismatchException;
6
use Gandung\JWT\TokenValidator\ClaimHeader;
7
8
/**
9
 * @author Paulus Gandung Prakosa <[email protected]>
10
 */
11
class ClaimBuilder implements ClaimBuilderInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    private $claim = [];
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function issuedBy($issuer)
22
    {
23
        return $this->collectClaim(Claim::ISSUER, (string)$issuer);
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function relatedTo($subject)
30
    {
31
        return $this->collectClaim(Claim::SUBJECT, $subject);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function intendedFor($audience)
38
    {
39
        return $this->collectClaim(Claim::AUDIENCE, $audience);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function expireAt(\DateTimeImmutable $expire)
46
    {
47
        return $this->collectClaim(Claim::EXPIRATION_TIME, $expire);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function canOnlyBeUsedAfter(\DateTimeImmutable $notBefore)
54
    {
55
        return $this->collectClaim(Claim::NOT_BEFORE, $notBefore);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function issuedAt(\DateTimeImmutable $issuedAt)
62
    {
63
        return $this->collectClaim(Claim::ISSUED_AT, $issuedAt);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function identifiedBy($id)
70
    {
71
        return $this->collectClaim(Claim::JWT_ID, $id);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getValue()
78
    {
79
        if (isset($this->claim[Claim::EXPIRATION_TIME]) &&
80
            $this->claim[Claim::EXPIRATION_TIME] instanceof \DateTimeInterface) {
81
            $this->claim[Claim::EXPIRATION_TIME] = (int)$this->claim[Claim::EXPIRATION_TIME]->format('U');
82
        }
83
84
        if (isset($this->claim[Claim::NOT_BEFORE]) &&
85
            $this->claim[Claim::NOT_BEFORE] instanceof \DateTimeInterface) {
86
            $this->claim[Claim::NOT_BEFORE] = (int)$this->claim[Claim::NOT_BEFORE]->format('U');
87
        }
88
89
        if (isset($this->claim[Claim::ISSUED_AT]) &&
90
            $this->claim[Claim::ISSUED_AT] instanceof \DateTimeInterface) {
91
            $this->claim[Claim::ISSUED_AT] = (int)$this->claim[Claim::ISSUED_AT]->format('U');
92
        }
93
        
94
        return $this->claim;
95
    }
96
    
97
    /**
98
     * Aggregate JWT claims list by pairing supplied claim into it's value.
99
     *
100
     * @param string $name
101
     * @param mixed $value
102
     * @return this
103
     */
104
    private function collectClaim($name, $value)
105
    {
106
        if (!ClaimHeader::create()->validate($name)) {
107
            throw new ClaimTokenMismatchException("Supply valid claim header name.");
108
        }
109
        
110
        $this->claim[$name] = $value;
111
112
        return $this;
113
    }
114
}
115