UrlSafeB64Encoder::decode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the tmilos/jose-jwt package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\JoseJwt\Util;
13
14
class UrlSafeB64Encoder
15
{
16
    /**
17
     * @param string $data
18
     *
19
     * @return string
20
     */
21
    public static function encode($data)
22
    {
23
        $b64 = base64_encode($data);
24
        $b64 = str_replace(
25
            array('+', '/', '\r', '\n', '='),
26
            array('-', '_'),
27
            $b64
28
        );
29
30
        return $b64;
31
    }
32
33
    /**
34
     * @param string $b64
35
     *
36
     * @return string
37
     */
38
    public static function decode($b64)
39
    {
40
        $b64 = str_replace(
41
            array('-', '_'),
42
            array('+', '/'),
43
            $b64
44
        );
45
46
        return base64_decode($b64);
47
    }
48
}
49