UrlHelper::queryParameters()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
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 12
    public function queryParameters() : array
20
    {
21 12
        $queryString = \request()->getQueryString();
22
23 12
        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
}