SanitizeParameters::rawurlencode()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 1
nop 1
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 2
rs 9.7
c 0
b 0
f 0
1
<?php
2
3
namespace Thinktomorrow\Locale\Parsers;
4
5
class SanitizeParameters
6
{
7
    /**
8
     * Loop over the parameters and make sure they are properly url encoded.
9
     *
10
     * @param array $parameters
11
     *
12
     * @return array
13
     */
14 31
    public static function rawurlencode(array $parameters): array
15
    {
16
        return array_map(function ($param) {
17
            // Null values are kept as is, so they'll get properly removed.
18 20
            if (null === $param) {
19 1
                return $param;
20
            }
21
22 20
            $param = rawurlencode($param);
23
24 20
            $param = str_replace('%2F', '/', $param);
25 20
            $param = str_replace('%3F', '?', $param);
26 20
            $param = str_replace('%3D', '=', $param);
27
28 20
            return $param;
29 31
        }, $parameters);
30
    }
31
}
32