Completed
Pull Request — master (#84)
by
unknown
02:04
created

Query   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 33
ccs 0
cts 22
cp 0
rs 10
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 ?string $query = null;
17
18
    public function __construct(?string $query = null)
19
    {
20
        $this->query = $query;
21
    }
22
23
    public function getQuery(): string
24
    {
25
        $this->initialize();
26
27
        return http_build_query($this->data);
28
    }
29
30
    public function setQuery(string $query): void
31
    {
32
        $this->initialized = false;
33
        $this->query       = $query;
34
    }
35
36
    public function __toString(): string
37
    {
38
        return $this->getQuery();
39
    }
40
41
    protected function doInitialize(): void
42
    {
43
        parse_str((string) $this->query, $data);
44
45
        $this->data = $data;
46
    }
47
}
48