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.

Base64::encode()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
namespace Emarref\Jwt\Encoding;
4
5
class Base64 implements EncoderInterface
6
{
7
    /**
8
     * @var boolean
9
     */
10
    private $urlSafe;
11
12
    /**
13
     * @var boolean
14
     */
15
    private $strict;
16
17
    /**
18
     * @var array
19
     */
20
    private static $urlSafeReplacements = [
21
        '+' => '-',
22
        '/' => '_'
23
    ];
24
25
    /**
26
     * @param boolean $urlSafe
27
     * @param boolean $strict
28
     */
29
    public function __construct($urlSafe = true, $strict = true)
30
    {
31
        $this->urlSafe = (boolean)$urlSafe;
32
        $this->strict  = (boolean)$strict;
33
    }
34
35
    /**
36
     * Return a URL-safe representation of a base64-encoded value.
37
     *
38
     * @param string $value
39
     * @return string
40
     */
41
    protected function urlEncode($value)
42
    {
43
        return strtr(rtrim($value, '='), self::$urlSafeReplacements);
44
    }
45
46
    /**
47
     * @param string $value
48
     * @return string
49
     */
50
    protected function urlDecode($value)
51
    {
52
        $urlUnsafeReplacements = array_flip(self::$urlSafeReplacements);
53
54
        $value = strtr($value, $urlUnsafeReplacements);
55
56
        switch (strlen($value) % 4) {
57
            case 0:
58
                // No pad chars in this case
59
                break;
60
            case 2:
61
                $value .= '==';
62
                break;
63
            case 3:
64
                $value .= '=';
65
                break;
66
            case 1:
67
            default:
68
                throw new \RuntimeException('Value could not be decoded from URL safe representation.');
69
        }
70
71
        return $value;
72
    }
73
74
    /**
75
     * @param string $value
76
     * @return string
77
     */
78
    public function encode($value)
79
    {
80
        if (empty($value)) {
81
            return '';
82
        }
83
84
        $encoded = base64_encode($value);
85
86
        if ($this->urlSafe) {
87
            $encoded = $this->urlEncode($encoded);
88
        }
89
90
        return $encoded;
91
    }
92
93
    /**
94
     * @param string $value
95
     * @return string
96
     */
97
    public function decode($value)
98
    {
99
        if (empty($value)) {
100
            return $value;
101
        }
102
103
        if ($this->urlSafe) {
104
            $decoded = $this->urlDecode($value);
105
        } else {
106
            $decoded = $value;
107
        }
108
109
        $decoded = base64_decode($decoded, $this->strict);
110
111
        return $decoded;
112
    }
113
}
114