UrlEncoder::decode()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 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