UrlHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _extractQueryParameters() 0 15 3
A queryParameters() 0 5 2
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
}