Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Base64
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
6 / 6
8
100.00% covered (success)
100.00%
1 / 1
 encodeUrl
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 encode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 encodeUrlCharacters
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 decodeUrl
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 decode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 decodeUrlCharacters
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Projom\Util;
6
7class Base64
8{
9    public static function encodeUrl(string $string): string
10    {
11        if (!$string)
12            return '';
13
14        $string = static::encode($string);
15        return static::encodeUrlCharacters($string);
16    }
17
18    public static function encode(string $string): string
19    {
20        return base64_encode($string);
21    }
22
23    public static function encodeUrlCharacters(string $string): string
24    {
25        return str_replace(['+', '/', '='], ['-', '_', ''], $string);
26    }
27
28    public static function decodeUrl(string $string): string
29    {
30        if (!$string)
31            return '';
32
33        $string = static::decodeUrlCharacters($string);
34        return static::decode($string);
35    }
36
37    public static function decode(string $string): string
38    {
39        return base64_decode($string);
40    }
41
42    public static function decodeUrlCharacters(string $string): string
43    {
44        return str_replace(['-', '_'], ['+', '/'], $string);
45    }
46}