Query   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A doInitialize() 0 5 1
A __toString() 0 3 1
A setQuery() 0 4 1
A getQuery() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Purl;
6
7
use function http_build_query;
8
use function parse_str;
9
10
/**
11
 * Query represents the part of a Url after the question mark (?).
12
 */
13
class Query extends AbstractPart
14
{
15
    /** @var string|null The original query string. */
16
    private $query;
17
18 45
    public function __construct(?string $query = null)
19
    {
20 45
        $this->query = $query;
21 45
    }
22
23 32
    public function getQuery() : string
24
    {
25 32
        $this->initialize();
26
27 32
        return http_build_query($this->data);
28
    }
29
30 1
    public function setQuery(string $query) : void
31
    {
32 1
        $this->initialized = false;
33 1
        $this->query       = $query;
34 1
    }
35
36 29
    public function __toString() : string
37
    {
38 29
        return $this->getQuery();
39
    }
40
41 32
    protected function doInitialize() : void
42
    {
43 32
        parse_str((string) $this->query, $data);
44
45 32
        $this->data = $data;
46 32
    }
47
}
48