UrlEncoder   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 40
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 13 3
A decode() 0 13 3
1
<?php
2
/**
3
 *  This file is part of the Simple S3 package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
namespace Matecat\SimpleS3\Components\Encoders;
13
14
class UrlEncoder extends SafeNameEncoder
15
{
16
    /**
17
     * @param string $string
18
     *
19
     * @return string
20
     */
21 1
    public function decode($string)
22
    {
23 1
        $decoded = [];
24
25 1
        foreach (explode(DIRECTORY_SEPARATOR, $string) as $word) {
26 1
            if (false === $this->isASafeString($word)) {
27 1
                $word = urldecode($word);
28
            }
29
30 1
            $decoded[] = $word;
31
        }
32
33 1
        return implode(DIRECTORY_SEPARATOR, $decoded);
34
    }
35
36
    /**
37
     * @param string $string
38
     *
39
     * @return string
40
     */
41 5
    public function encode($string)
42
    {
43 5
        $encoded = [];
44
45 5
        foreach (explode(DIRECTORY_SEPARATOR, $string) as $word) {
46 5
            if (false === $this->isASafeString($word)) {
47 4
                $word = urlencode($word);
48
            }
49
50 5
            $encoded[] = $word;
51
        }
52
53 5
        return implode(DIRECTORY_SEPARATOR, $encoded);
54
    }
55
}
56