Completed
Push — master ( ffa818...f511c0 )
by Timo
07:51
created

UrlHelper::parameterizeQuery()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 1
crap 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A UrlHelper::__construct() 0 4 1
1
<?php
2
3
namespace hamburgscleanest\DataTables\Helpers;
4
5
use Illuminate\Http\Request;
6
use RuntimeException;
7
8
/**
9
 * Class UrlHelper
10
 * @package hamburgscleanest\DataTables\Helpers
11
 */
12
class UrlHelper {
13
14
    /** @var Request */
15
    private $_request;
16
17
    /**
18
     * UrlHelper constructor.
19
     * @param Request $request
20
     */
21 16
    public function __construct(Request $request)
1 ignored issue
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
22
    {
23 16
        $this->_request = $request;
24 16
    }
25
26
    /**
27
     * Array of all the query parameters for the current request.
28
     *
29
     * @return array
30
     * @throws \RuntimeException
31
     */
32 11
    public function queryParameters() : array
33
    {
34 11
        $queryString = $this->_request->getQueryString();
35
36 11
        if (empty($queryString))
37
        {
38 9
            return [];
39
        }
40
41 2
        $parameters = [];
42 2
        foreach (\explode('&', $queryString) as $query)
43
        {
44 2
            $queryParts = \explode('=', $query);
45 2
            if (\count($queryParts) !== 2)
46
            {
47 1
                throw new RuntimeException('Malformed query parameters.');
48
            }
49
50 1
            $parameters[$queryParts[0]] = $queryParts[1];
51
        }
52
53 1
        return $parameters;
54
    }
55
}