Completed
Branch master (a2d832)
by Timo
02:40
created

UrlHelper::parameterizeQuery()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 9.488

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 3
cts 10
cp 0.3
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 1
crap 9.488
1
<?php
2
3
namespace hamburgscleanest\DataTables\Helpers;
4
5
use RuntimeException;
6
7
/**
8
 * Class UrlHelper
9
 * @package hamburgscleanest\DataTables\Helpers
10
 *
11
 * TODO: Facade?
12
 */
13
class UrlHelper {
14
15
    /**
16
     * @param string|null $queryString
17
     *
18
     * @return array
19
     * @throws \RuntimeException
20
     */
21 1
    public static function parameterizeQuery(? string $queryString = null)
22
    {
23 1
        if (empty($queryString))
24
        {
25 1
            return [];
26
        }
27
28
        $parameters = [];
29
        foreach (\explode('&', $queryString) as $query)
30
        {
31
            $queryParts = \explode('=', $query);
32
            if (\count($queryParts) !== 2)
33
            {
34
                throw new RuntimeException('Malformed query parameters.');
35
            }
36
37
            $parameters[$queryParts[0]] = $queryParts[1];
38
        }
39
40
        return $parameters;
41
    }
42
}