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.
Completed
Pull Request — master (#23)
by Malcolm
04:22 queued 02:10
created

Token::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
namespace Emarref\Jwt;
4
5
use Emarref\Jwt\Claim;
6
use Emarref\Jwt\HeaderParameter;
7
use Emarref\Jwt\Token\AbstractTokenBody;
8
use Emarref\Jwt\Token\Header;
9
use Emarref\Jwt\Token\Payload;
10
11
class Token
12
{
13
    const OPT_JSON_ESCAPE_SLASHES = 'json_escape_slashes';
14
15
    /**
16
     * @var Header
17
     */
18
    private $header;
19
20
    /**
21
     * @var Payload
22
     */
23
    private $payload;
24
25
    /**
26
     * @var string
27
     */
28
    private $signature;
29
30
    /**
31
     * @param array $options
32
     */
33
    public function __construct(array $options = [])
34
    {
35
        $options = $this->parseOptions($options);
36
37
        $sectionOptions = [];
38
39
        if (false === (bool)$options[self::OPT_JSON_ESCAPE_SLASHES]) {
40
            $sectionOptions = [
41
                AbstractTokenBody::OPT_JSON_OPTIONS => JSON_UNESCAPED_SLASHES
42
            ];
43
        }
44
45
        $this->header  = new Header($sectionOptions);
46
        $this->payload = new Payload($sectionOptions);
47
    }
48
49
    /**
50
     * @param array $options
51
     * @return array
52
     */
53
    protected function parseOptions(array $options)
54
    {
55
        $defaultOptions = $this->getDefaultOptions();
56
57
        return array_merge($defaultOptions, $options);
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    protected function getDefaultOptions()
64
    {
65
        return [
66
            self::OPT_JSON_ESCAPE_SLASHES => false,
67
        ];
68
    }
69
70
    /**
71
     * @param HeaderParameter\ParameterInterface $parameter
72
     * @param bool                               $critical
73
     */
74
    public function addHeader(HeaderParameter\ParameterInterface $parameter, $critical = false)
75
    {
76
        $this->header->setParameter($parameter, $critical);
77
    }
78
79
    /**
80
     * @param Claim\ClaimInterface $claim
81
     */
82
    public function addClaim(Claim\ClaimInterface $claim)
83
    {
84
        $this->payload->setClaim($claim);
85
    }
86
87
    /**
88
     * @return Token\Header
89
     */
90
    public function getHeader()
91
    {
92
        return $this->header;
93
    }
94
95
    /**
96
     * @return Token\Payload
97
     */
98
    public function getPayload()
99
    {
100
        return $this->payload;
101
    }
102
103
    /**
104
     * @return string
105
     */
106
    public function getSignature()
107
    {
108
        return $this->signature;
109
    }
110
111
    /**
112
     * @param string $signature
113
     */
114
    public function setSignature($signature)
115
    {
116
        $this->signature = $signature;
117
    }
118
}
119