Base64   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 50
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 4 1
A decode() 0 4 1
A encode_unpadded() 0 4 1
A decode_unpadded() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Icybee package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Icybee\Modules\Files\Storage;
13
14
/**
15
 * Base64 support.
16
 */
17
class Base64
18
{
19
	/**
20
	 * Encodes data as base64url.
21
	 *
22
	 * @param string $data
23
	 *
24
	 * @return string
25
	 */
26
	static public function encode($data)
27
	{
28
		return strtr(base64_encode($data), [ '+' => '-', '/' => '_' ]);
29
	}
30
31
	/**
32
	 * Decodes base64url data.
33
	 *
34
	 * @param string $data
35
	 *
36
	 * @return string
37
	 */
38
	static public function decode($data)
39
	{
40
		return base64_decode(strtr($data, [ '-' => '+', '_' => '/' ]));
41
	}
42
43
	/**
44
	 * Encodes data as base64url, removes padding character.
45
	 *
46
	 * @param string $data
47
	 *
48
	 * @return string
49
	 */
50
	static public function encode_unpadded($data)
51
	{
52
		return rtrim(self::encode($data), '=');
53
	}
54
55
	/**
56
	 * Decodes unpadded base64url.
57
	 *
58
	 * @param string $data
59
	 *
60
	 * @return string
61
	 */
62
	static public function decode_unpadded($data)
63
	{
64
		return self::decode($data);
65
	}
66
}
67