UrlSafeB64Encoder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 11 1
A decode() 0 10 1
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