Completed
Push — master ( 895c5c...49cc4e )
by Timo
11:39
created

UrlHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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