Completed
Branch master (005f57)
by Timo
02:33
created

UrlHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parameterizeQuery() 0 21 4
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 3
    public static function parameterizeQuery(? string $queryString = null)
22
    {
23 3
        if (empty($queryString))
24
        {
25 1
            return [];
26
        }
27
28 2
        $parameters = [];
29 2
        foreach (\explode('&', $queryString) as $query)
30
        {
31 2
            $queryParts = \explode('=', $query);
32 2
            if (\count($queryParts) !== 2)
33
            {
34 1
                throw new RuntimeException('Malformed query parameters.');
35
            }
36
37 1
            $parameters[$queryParts[0]] = $queryParts[1];
38
        }
39
40 1
        return $parameters;
41
    }
42
}