Query::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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